Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mon 12065 async engine 21.10 #129

Merged
merged 4 commits into from
Jan 18, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix(multiplexing/engine): operation not atomic fixed
  • Loading branch information
bouda1 committed Jan 15, 2022
commit f240968b6463c1e5e50238b04fc0e529a85e3d23
17 changes: 8 additions & 9 deletions centreon-broker/core/src/multiplexing/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,11 @@ void engine::_send_to_subscribers() {
std::swap(_kiew, kiew);
}

std::atomic<size_t> count{_muxers.size()};
if (count > 0) {
std::atomic<int> count{static_cast<int>(_muxers.size()) - 1};
std::promise<void> promise;
if (count >= 0) {
/* We must wait the end of the sending, so we use a promise. */
std::promise<void> promise;
auto future = promise.get_future();

/* Since the sending is parallelized, we use the thread pool for this
* purpose except for the last muxer where we use this thread. */
Expand All @@ -308,21 +309,19 @@ void engine::_send_to_subscribers() {
pool::io_context().post([&kiew, m = *it, &count, &promise] {
for (auto& e : kiew)
m->publish(e);
--count;
if (count == 0)
if (atomic_fetch_sub_explicit(&count, 1, std::memory_order_relaxed) ==
0)
promise.set_value();
});
}
/* The same work but by this thread for the last muxer. */
auto m = *it_last;
for (auto& e : kiew)
m->publish(e);
--count;

if (count == 0)
if (atomic_fetch_sub_explicit(&count, 1, std::memory_order_relaxed) == 0)
promise.set_value();

promise.get_future().get();
future.wait();
}

/* The strand is necessary for the order of data */
Expand Down