2 // SPDX-License-Identifier: BSD-3-Clause
3 // Copyright Contributors to the OpenEXR Project.
8 #include "PyImathTask.h"
12 static WorkerPool *_currentPool = nullptr;
14 // Its not worth dispatching parallel tasks unless the iteration count
15 // is high enough. The time to create and launch parallel tasks takes
16 // longer than to just do the iterations directly. This value of '200'
17 // is actually very conservative; in some tests, this number should
18 // probably be in the thousands.
19 static const size_t _minIterations = 200;
22 WorkerPool::currentPool()
28 WorkerPool::setCurrentPool(WorkerPool *pool)
34 dispatchTask(Task &task,size_t length)
36 if (length > _minIterations)
38 WorkerPool *curpool = WorkerPool::currentPool();
39 if (curpool && !curpool->inWorkerThread())
41 curpool->dispatch(task,length);
45 task.execute(0,length,0);
52 WorkerPool *curpool = WorkerPool::currentPool();
53 if (curpool && !curpool->inWorkerThread())
54 return curpool->workers();