Add TaskSettings overloads for runWorkerTaskDist(H).

This commit is contained in:
Sönke Ludwig 2020-03-14 23:33:41 +01:00
parent a6bd4a0b1d
commit 262b417794
2 changed files with 27 additions and 1 deletions

View file

@ -656,6 +656,19 @@ void runWorkerTaskDist(alias method, T, ARGS...)(shared(T) object, ARGS args)
setupWorkerThreads();
return st_workerPool.runTaskDist!method(object, args);
}
/// ditto
void runWorkerTaskDist(FT, ARGS...)(TaskSettings settings, FT func, auto ref ARGS args)
if (is(typeof(*func) == function))
{
setupWorkerThreads();
return st_workerPool.runTaskDist(settings, func, args);
}
/// ditto
void runWorkerTaskDist(alias method, T, ARGS...)(TaskSettings settings, shared(T) object, ARGS args)
{
setupWorkerThreads();
return st_workerPool.runTaskDist!method(settings, object, args);
}
/** Runs a new asynchronous task in all worker threads and returns the handles.
@ -671,6 +684,13 @@ void runWorkerTaskDistH(HCB, FT, ARGS...)(scope HCB on_handle, FT func, auto ref
setupWorkerThreads();
st_workerPool.runTaskDistH(on_handle, func, args);
}
/// ditto
void runWorkerTaskDistH(HCB, FT, ARGS...)(TaskSettings settings, scope HCB on_handle, FT func, auto ref ARGS args)
if (is(typeof(*func) == function))
{
setupWorkerThreads();
st_workerPool.runTaskDistH(settings, on_handle, func, args);
}
/**

View file

@ -261,6 +261,12 @@ shared final class TaskPool {
See_also: `runTaskDist`
*/
void runTaskDistH(HCB, FT, ARGS...)(scope HCB on_handle, FT func, auto ref ARGS args)
if (!is(HCB == TaskSettings))
{
runTaskDistH(TaskSettings.init, on_handle, func, args);
}
/// ditto
void runTaskDistH(HCB, FT, ARGS...)(TaskSettings settings, scope HCB on_handle, FT func, auto ref ARGS args)
{
// TODO: support non-copyable argument types using .move
import std.concurrency : send, receiveOnly;
@ -277,7 +283,7 @@ shared final class TaskPool {
t.tid.send(Task.getThis());
func(args);
}
runTaskDist(&call, caller, func, args);
runTaskDist(settings, &call, caller, func, args);
foreach (i; 0 .. this.threadCount)
on_handle(receiveOnly!Task);