/** Wait for worker threads to exit */ void WaitExit() { boost::unique_lock<boost::mutex> lock(cs); while (numThreads > 0){ cond.wait(lock); } }
/** Enqueue a work item */ bool Enqueue(WorkItem* item) { boost::unique_lock<boost::mutex> lock(cs); if (queue.size() >= maxDepth) { return false; } queue.push_back(item); cond.notify_one(); return true; }
/** Enqueue a work item */ bool Enqueue(WorkItem* item) { boost::unique_lock<boost::mutex> lock(cs); if (queue.size() >= maxDepth) { return false; } queue.emplace_back(std::unique_ptr<WorkItem>(item)); cond.notify_one(); return true; }
/** Thread function */ void Run() { ThreadCounter count(*this); while (running) { std::unique_ptr<WorkItem> i; { boost::unique_lock<boost::mutex> lock(cs); while (running && queue.empty()) cond.wait(lock); if (!running) break; i = std::move(queue.front()); queue.pop_front(); } (*i)(); } }
/** Thread function */ void Run() { ThreadCounter count(*this); while (running) { WorkItem* i = 0; { boost::unique_lock<boost::mutex> lock(cs); while (running && queue.empty()) cond.wait(lock); if (!running) break; i = queue.front(); queue.pop_front(); } (*i)(); delete i; } }
/** Interrupt and exit loops */ void Interrupt() { boost::unique_lock<boost::mutex> lock(cs); running = false; cond.notify_all(); }