Fix workerThreadCount to return the actual number of threads in the default worker pool. Fixes #35.

This commit is contained in:
Sönke Ludwig 2017-09-21 13:39:05 +02:00
parent 0dbebac482
commit dd05676c4e

View file

@ -859,7 +859,8 @@ nothrow {
out(count) { assert(count > 0, "No worker threads started after setupWorkerThreads!?"); } out(count) { assert(count > 0, "No worker threads started after setupWorkerThreads!?"); }
body { body {
setupWorkerThreads(); setupWorkerThreads();
return st_threads.count!(c => c.isWorker); synchronized (st_threadsMutex)
return st_workerPool.threadCount;
} }
@ -1178,9 +1179,6 @@ package(vibe) void performIdleProcessing()
private struct ThreadContext { private struct ThreadContext {
Thread thread; Thread thread;
bool isWorker;
this(Thread thr, bool worker) { this.thread = thr; this.isWorker = worker; }
} }
/**************************************************************************************************/ /**************************************************************************************************/
@ -1311,7 +1309,7 @@ shared static this()
auto thisthr = Thread.getThis(); auto thisthr = Thread.getThis();
thisthr.name = "main"; thisthr.name = "main";
assert(st_threads.length == 0, "Main thread not the first thread!?"); assert(st_threads.length == 0, "Main thread not the first thread!?");
st_threads ~= ThreadContext(thisthr, false); st_threads ~= ThreadContext(thisthr);
st_threadsSignal = createSharedManualEvent(); st_threadsSignal = createSharedManualEvent();
@ -1354,7 +1352,7 @@ static this()
auto thisthr = Thread.getThis(); auto thisthr = Thread.getThis();
synchronized (st_threadsMutex) synchronized (st_threadsMutex)
if (!st_threads.any!(c => c.thread is thisthr)) if (!st_threads.any!(c => c.thread is thisthr))
st_threads ~= ThreadContext(thisthr, false); st_threads ~= ThreadContext(thisthr);
import vibe.core.sync : SpinLock; import vibe.core.sync : SpinLock;