From 494a8a660ac394d0ae560585443561e4c3c6c2bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Mon, 18 Mar 2019 23:37:08 +0200 Subject: [PATCH] Improve RoutingWorker utilities Added an overload to execute_concurrently that takes an std::function as a parameter and added a const version of operator* for rworker_local. Also removed the std::move of the return value in rworker_local::values as it can prevent RVO from taking place. --- include/maxscale/routingworker.hh | 9 ++++++++- server/core/routingworker.cc | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/maxscale/routingworker.hh b/include/maxscale/routingworker.hh index 5a55d76e7..0688a4e67 100644 --- a/include/maxscale/routingworker.hh +++ b/include/maxscale/routingworker.hh @@ -405,6 +405,7 @@ public: * otherwise the task is delivered via the message loop. */ static size_t execute_concurrently(Task& task); + static size_t execute_concurrently(std::function func); /** * Broadcast a message to all worker. @@ -705,6 +706,12 @@ public: return *get_local_value(); } + // Const version of dereference operator + const T& operator*() const + { + return *get_local_value(); + } + /** * Assign a value * @@ -746,7 +753,7 @@ public: RoutingWorker::EXECUTE_AUTO); sem.wait_n(n); - return std::move(rval); + return rval; } private: diff --git a/server/core/routingworker.cc b/server/core/routingworker.cc index 1ef8776df..d6a59e091 100644 --- a/server/core/routingworker.cc +++ b/server/core/routingworker.cc @@ -780,6 +780,13 @@ size_t RoutingWorker::execute_concurrently(Task& task) return sem.wait_n(RoutingWorker::broadcast(&task, &sem)); } +// static +size_t RoutingWorker::execute_concurrently(std::function func) +{ + Semaphore sem; + return sem.wait_n(RoutingWorker::broadcast(func, &sem, EXECUTE_AUTO)); +} + // static size_t RoutingWorker::broadcast_message(uint32_t msg_id, intptr_t arg1, intptr_t arg2) {