Skip to content
Merged
Changes from all commits
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
16 changes: 8 additions & 8 deletions source/common/thread_local/thread_local_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ void InstanceImpl::runOnAllThreads(Event::PostCb cb, Event::PostCb all_threads_c
// all_threads_complete_cb method. Parallelism of main thread execution is being traded off
// for programming simplicity here.
cb();
std::shared_ptr<std::atomic<uint64_t>> worker_count =
std::make_shared<std::atomic<uint64_t>>(registered_threads_.size());

std::shared_ptr<Event::PostCb> cb_guard(new Event::PostCb(cb),
[this, all_threads_complete_cb](Event::PostCb* cb) {
main_thread_dispatcher_->post(all_threads_complete_cb);
delete cb;
});

for (Event::Dispatcher& dispatcher : registered_threads_) {
dispatcher.post([this, worker_count, cb, all_threads_complete_cb]() -> void {
cb();
if (--*worker_count == 0) {
main_thread_dispatcher_->post(all_threads_complete_cb);
}
});
dispatcher.post([cb_guard]() -> void { (*cb_guard)(); });
}
}

Expand Down