MXS-2363 Enable the serial execution of function objects
Make it possible to run function objects serially on all routing workers. Sometimes that is exactly what you want.
This commit is contained in:
parent
9ec82932cf
commit
56ec56f7a0
@ -388,6 +388,7 @@ public:
|
||||
* otherwise the task is delivered via the message loop.
|
||||
*/
|
||||
static size_t execute_serially(Task& task);
|
||||
static size_t execute_serially(std::function<void()> func);
|
||||
|
||||
/**
|
||||
* Executes a task on all workers concurrently and waits until all workers
|
||||
|
@ -773,6 +773,28 @@ size_t RoutingWorker::execute_serially(Task& task)
|
||||
return n;
|
||||
}
|
||||
|
||||
//static
|
||||
size_t RoutingWorker::execute_serially(std::function<void()> func)
|
||||
{
|
||||
Semaphore sem;
|
||||
size_t n = 0;
|
||||
|
||||
int nWorkers = this_unit.next_worker_id;
|
||||
for (int i = 0; i < nWorkers; ++i)
|
||||
{
|
||||
RoutingWorker* pWorker = this_unit.ppWorkers[i];
|
||||
mxb_assert(pWorker);
|
||||
|
||||
if (pWorker->execute(func, &sem, EXECUTE_AUTO))
|
||||
{
|
||||
sem.wait();
|
||||
++n;
|
||||
}
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
// static
|
||||
size_t RoutingWorker::execute_concurrently(Task& task)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user