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.
This commit is contained in:
Johan Wikman
2017-04-29 08:22:32 +03:00
parent bfd94c2b31
commit 1b58a75f42
2 changed files with 18 additions and 0 deletions

View File

@ -338,6 +338,16 @@ public:
*/ */
static size_t execute_on_all_serially(Task* pTask); 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. * Post a message to a worker.
* *

View File

@ -618,6 +618,7 @@ size_t Worker::execute_on_all(std::auto_ptr<DisposableTask> sTask)
return n; return n;
} }
//static //static
size_t Worker::execute_on_all_serially(Task* pTask) size_t Worker::execute_on_all_serially(Task* pTask)
{ {
@ -638,6 +639,13 @@ size_t Worker::execute_on_all_serially(Task* pTask)
return n; 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) bool Worker::post_message(uint32_t msg_id, intptr_t arg1, intptr_t arg2)
{ {
// NOTE: No logging here, this function must be signal safe. // NOTE: No logging here, this function must be signal safe.