ThreadPoolTaskExecutor::WorkQueue ThreadPoolTaskExecutor::makeSingletonWorkQueue(CallbackFn work, Date_t when) { WorkQueue result; result.emplace_front(CallbackState::make(std::move(work), when)); result.front()->iter = result.begin(); return result; }
void AsyncThreadManager::itemConsumer(WorkQueue& workQueue, condition_variable& workAvailable, recursive_mutex& queueMutex, bool &finished) { while(true) { cz::unique_lock<cz::recursive_mutex> queueLock(queueMutex); while(!finished && workQueue.empty()) workAvailable.wait(queueLock); if (finished) break; detail::AsyncWorkItemBase* workItem = workQueue.front(); workQueue.pop(); // unlock so other threads can remove work items while we compute this one queueLock.unlock(); // Compute the result (this will put the value in the "future" object the user is holding) workItem->run(); CZ_DELETE workItem; } }