Allow serial execution of worker tasks
The Worker::execute_on_all_wait is intended to be used with dcb_foreach which expects a single-threaded context for its function.
This commit is contained in:
parent
ea39b15bbb
commit
963ff0216d
@ -320,6 +320,21 @@ public:
|
||||
*/
|
||||
static size_t execute_on_all(std::auto_ptr<DisposableTask> sTask);
|
||||
|
||||
/**
|
||||
* Executes a task on all workers in serial mode.
|
||||
*
|
||||
* The task is executed on at most one worker thread at a time.
|
||||
*
|
||||
* @param pTask The task to be executed.
|
||||
*
|
||||
* @return How many workers the task was posted to.
|
||||
*
|
||||
* @warning This function is extremely inefficient and will be slow compared
|
||||
* to the other functions. Only use this function when printing thread-specific
|
||||
* data to stdout.
|
||||
*/
|
||||
static size_t execute_on_all_serially(Task* pTask);
|
||||
|
||||
/**
|
||||
* Post a message to a worker.
|
||||
*
|
||||
|
@ -603,6 +603,25 @@ size_t Worker::execute_on_all(std::auto_ptr<DisposableTask> sTask)
|
||||
|
||||
return n;
|
||||
}
|
||||
//static
|
||||
size_t Worker::execute_on_all_serially(Task* pTask)
|
||||
{
|
||||
Semaphore sem;
|
||||
size_t n = 0;
|
||||
|
||||
for (int i = 0; i < this_unit.n_workers; ++i)
|
||||
{
|
||||
Worker* pWorker = this_unit.ppWorkers[i];
|
||||
|
||||
if (pWorker->execute(pTask, &sem))
|
||||
{
|
||||
sem.wait();
|
||||
++n;
|
||||
}
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
bool Worker::post_message(uint32_t msg_id, intptr_t arg1, intptr_t arg2)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user