Commit 3ed1b937 authored by Jakob Otto's avatar Jakob Otto

Fix shutdown routine

parent 2c46b07f
......@@ -61,6 +61,8 @@ public:
/// Returns the index of `mgr` in the pollset or `-1`.
ptrdiff_t index_of(const socket_manager_ptr& mgr);
bool is_same_thread();
// -- thread-safe signaling --------------------------------------------------
/// Registers `mgr` for read events.
......
......@@ -104,6 +104,10 @@ ptrdiff_t multiplexer::index_of(const socket_manager_ptr& mgr) {
return i == last ? -1 : std::distance(first, i);
}
bool multiplexer::is_same_thread() {
return std::this_thread::get_id() == tid_;
}
void multiplexer::register_reading(const socket_manager_ptr& mgr) {
if (std::this_thread::get_id() == tid_) {
if (mgr->mask() != operation::none) {
......@@ -242,7 +246,6 @@ void multiplexer::shutdown() {
}
} else {
write_to_pipe(5, nullptr);
run();
}
}
......
......@@ -55,7 +55,10 @@ void middleman::start() {
void middleman::stop() {
for (const auto& backend : backends_)
backend->stop();
if (mpx_thread_.joinable())
mpx_->shutdown();
if (mpx_->is_same_thread())
mpx_->run();
else if (mpx_thread_.joinable())
mpx_thread_.join();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment