From 1b58a75f42110e95804d50ef2eba9c0c93984dc0 Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Sat, 29 Apr 2017 08:22:32 +0300 Subject: [PATCH] Add concurrent execution helper to Worker Concurrently executing a task on all workers *and* waiting until all workers have executed the task seems to be common enough to warrant a helper function for that purpose. --- server/core/maxscale/worker.hh | 10 ++++++++++ server/core/worker.cc | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/server/core/maxscale/worker.hh b/server/core/maxscale/worker.hh index e2fa1c72b..859ae9847 100644 --- a/server/core/maxscale/worker.hh +++ b/server/core/maxscale/worker.hh @@ -338,6 +338,16 @@ public: */ static size_t execute_on_all_serially(Task* pTask); + /** + * Executes a task on all workers concurrently and waits until + * all workers are done. + * + * @param pTask The task to be executed. + * + * @return How many workers the task was posted to. + */ + static size_t execute_on_all_concurrently(Task* pTask); + /** * Post a message to a worker. * diff --git a/server/core/worker.cc b/server/core/worker.cc index 4b3e5ac1f..5f5ec135c 100644 --- a/server/core/worker.cc +++ b/server/core/worker.cc @@ -618,6 +618,7 @@ size_t Worker::execute_on_all(std::auto_ptr sTask) return n; } + //static size_t Worker::execute_on_all_serially(Task* pTask) { @@ -638,6 +639,13 @@ size_t Worker::execute_on_all_serially(Task* pTask) return n; } +//static +size_t Worker::execute_on_all_concurrently(Task* pTask) +{ + Semaphore sem; + return sem.wait_n(Worker::execute_on_all(pTask, &sem)); +} + bool Worker::post_message(uint32_t msg_id, intptr_t arg1, intptr_t arg2) { // NOTE: No logging here, this function must be signal safe.