Skip to content

Commit

Permalink
Don't use static constructors for registration.
Browse files Browse the repository at this point in the history
Doing so requires that seastar be linked as a shared library or using
--whole-archive.

Fixes scylladb#556.

Signed-off-by: Rafael Ávila de Espíndola <[email protected]>
Message-Id: <[email protected]>
  • Loading branch information
espindola authored and avikivity committed Dec 20, 2018
1 parent 40dd58b commit 9e27e4a
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 31 deletions.
11 changes: 3 additions & 8 deletions include/seastar/core/reactor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,9 @@ bool operator==(const ::sockaddr_in a, const ::sockaddr_in b);

namespace seastar {

class network_stack_registrator {
public:
using options = boost::program_options::variables_map;
explicit network_stack_registrator(sstring name,
boost::program_options::options_description opts,
std::function<future<std::unique_ptr<network_stack>> (options opts)> factory,
bool make_default = false);
};
void register_network_stack(sstring name, boost::program_options::options_description opts,
std::function<future<std::unique_ptr<network_stack>>(boost::program_options::variables_map opts)> create,
bool make_default = false);

class writeable_eventfd;

Expand Down
1 change: 1 addition & 0 deletions include/seastar/net/native-stack.hh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace seastar {
namespace net {

void create_native_stack(boost::program_options::variables_map opts, std::shared_ptr<device> dev);
void register_native_stack();

}

Expand Down
1 change: 1 addition & 0 deletions include/seastar/net/posix-stack.hh
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ public:
}
};

void register_posix_stack();
}

}
37 changes: 18 additions & 19 deletions src/core/reactor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <seastar/net/packet.hh>
#include <seastar/net/stack.hh>
#include <seastar/net/posix-stack.hh>
#include <seastar/net/native-stack.hh>
#include <seastar/core/resource.hh>
#include <seastar/core/print.hh>
#include "core/scollectd-impl.hh"
Expand Down Expand Up @@ -1267,10 +1268,9 @@ class network_stack_registry {
static boost::program_options::options_description opts;
return opts;
}
static void register_stack(sstring name,
boost::program_options::options_description opts,
std::function<future<std::unique_ptr<network_stack>> (options opts)> create,
bool make_default = false);
static void register_stack(sstring name, boost::program_options::options_description opts,
std::function<future<std::unique_ptr<network_stack>>(options opts)> create,
bool make_default);
static sstring default_stack();
static std::vector<sstring> list();
static future<std::unique_ptr<network_stack>> create(options opts);
Expand Down Expand Up @@ -4241,6 +4241,14 @@ void network_stack_registry::register_stack(sstring name,
}
}

void register_network_stack(sstring name, boost::program_options::options_description opts,
std::function<future<std::unique_ptr<network_stack>>(boost::program_options::variables_map)>
create,
bool make_default) {
return network_stack_registry::register_stack(
std::move(name), std::move(opts), std::move(create), make_default);
}

sstring network_stack_registry::default_stack() {
return _default();
}
Expand All @@ -4266,13 +4274,6 @@ network_stack_registry::create(sstring name, options opts) {
return _map()[name](opts);
}

network_stack_registrator::network_stack_registrator(sstring name,
boost::program_options::options_description opts,
std::function<future<std::unique_ptr<network_stack>>(options opts)> factory,
bool make_default) {
network_stack_registry::register_stack(name, opts, factory, make_default);
}

boost::program_options::options_description
reactor::get_options_description(std::chrono::duration<double> default_task_quota) {
namespace bpo = boost::program_options;
Expand Down Expand Up @@ -4630,8 +4631,14 @@ class disk_config_params {
}
};

static void register_network_stacks() {
register_posix_stack();
register_native_stack();
}

void smp::configure(boost::program_options::variables_map configuration)
{
register_network_stacks();
#ifndef SEASTAR_NO_EXCEPTION_HACK
if (configuration["enable-glibc-exception-scaling-workaround"].as<bool>()) {
init_phdr_cache();
Expand Down Expand Up @@ -5171,14 +5178,6 @@ void add_to_flush_poller(output_stream<char>* os) {
engine()._flush_batching.emplace_back(os);
}

network_stack_registrator nsr_posix{"posix",
boost::program_options::options_description(),
[](boost::program_options::variables_map ops) {
return smp::main_thread() ? posix_network_stack::create(ops) : posix_ap_network_stack::create(ops);
},
true
};

reactor::sched_clock::duration reactor::total_idle_time() {
return _total_idle;
}
Expand Down
7 changes: 3 additions & 4 deletions src/net/native-stack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,9 @@ boost::program_options::options_description nns_options() {
return opts;
}

network_stack_registrator nns_registrator{
"native", nns_options(), native_network_stack::create
};

void register_native_stack() {
register_network_stack("native", nns_options(), native_network_stack::create);
}
}

}
8 changes: 8 additions & 0 deletions src/net/posix-stack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,14 @@ posix_udp_channel::receive() {
});
}

void register_posix_stack() {
register_network_stack("posix", boost::program_options::options_description(),
[](boost::program_options::variables_map ops) {
return smp::main_thread() ? posix_network_stack::create(ops)
: posix_ap_network_stack::create(ops);
},
true);
}
}

}

0 comments on commit 9e27e4a

Please sign in to comment.