From 262b417794d38111e830a34c43281e55576f74aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Sat, 14 Mar 2020 23:33:41 +0100 Subject: [PATCH] Add TaskSettings overloads for runWorkerTaskDist(H). --- source/vibe/core/core.d | 20 ++++++++++++++++++++ source/vibe/core/taskpool.d | 8 +++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/source/vibe/core/core.d b/source/vibe/core/core.d index 2d1af35..953cbc4 100644 --- a/source/vibe/core/core.d +++ b/source/vibe/core/core.d @@ -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); +} /** diff --git a/source/vibe/core/taskpool.d b/source/vibe/core/taskpool.d index cd1aa67..f862ab5 100644 --- a/source/vibe/core/taskpool.d +++ b/source/vibe/core/taskpool.d @@ -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);