8 namespace honey {
namespace thread
35 void enqueue(
Task&& task) { enqueue_(TaskPtr(forward<Task>(task))); }
38 static Task*
current() {
auto& ptr = Worker::current()._task;
return ptr ? &(*ptr) :
nullptr; }
44 TaskPtr(nullptr_t) : TaskPtr() {}
46 TaskPtr(Task&& task) : mt::Funcptr<void ()>(forward<Task>(task)) {}
48 Task& operator*()
const {
assert(base);
return static_cast<Task&
>(*base); }
49 Task* operator->()
const {
assert(base);
return static_cast<Task*
>(base); }
59 static Worker&
current() {
assert(*_current);
return **_current; }
75 lockfree::Queue<TaskPtr> _tasks;
77 static thread::Local<Worker*> _current;
80 void enqueue_(TaskPtr task);
82 const szt _workerTaskMax;
83 vector<UniquePtr<Worker>> _workers;
84 lockfree::Queue<TaskPtr> _tasks;
friend class Worker
Definition: Pool.h:19
static Task * current()
Get the current task object of the calling thread. Must be called from inside a task, returns null otherwise.
Definition: Pool.h:38
Pool(szt workerCount, szt workerTaskMax)
Definition: Pool.cpp:24
Reference-counted object for intrusive shared pointers.
Definition: SharedPtr.h:93
~Pool()
Definition: Pool.cpp:31
#define assert(...)
Forwards to assert_#args. See assert_1(), assert_2().
Definition: Debug.h:24
Unicode UTF-16 string class, wrapper around std::u16string.
Definition: String.h:23
All tasks must inherit from this class. std::function is not used here to avoid the operator() virtua...
Definition: Pool.h:16
size_t szt
Size type, shorthand for size_t.
Definition: Core.h:90
void enqueue(Task &&task)
Schedule a task for execution.
Definition: Pool.h:35
Inherit to enable non-virtual functor calling.
Definition: Meta.h:231
Global Honeycomb namespace.
virtual void trace(const String &file, int line, const String &msg) const
Definition: Pool.cpp:16
virtual bool traceEnabled() const
Definition: Pool.h:23
Spreads task execution across a pool of re-usable threads. Uses a lock-free work-stealing queue to en...
Definition: Pool.h:12