5 #include "os_workqueue.hpp"
11 * return 0 on batch complete, -1 on thread exit request.
13 int WorkQueue::run_tasks(void)
15 os::unique_lock<os::mutex> lock(mutex);
17 while (work_queue.empty() && !exit_workqueue) {
25 std::queue<WorkQueueWork *> batch;
26 std::swap(work_queue, batch);
31 assert(!batch.empty());
32 while (!batch.empty()) {
44 complete_cond.signal();
49 /* Must be called with WorkQueue::lock held */
50 void WorkQueue::wake_up_thread(void)
55 void WorkQueue::queue_work(WorkQueueWork *task)
58 work_queue.push(task);
63 void WorkQueue::flush(void)
65 os::unique_lock<os::mutex> lock(mutex);
66 while (!work_queue.empty() || busy) {
67 complete_cond.wait(lock);
71 void WorkQueue::thread_entry(void)
80 void WorkQueue::destroy(void)
83 exit_workqueue = true;
89 void *WorkQueue__entry_thunk(void *data)
91 WorkQueue *thread = static_cast<WorkQueue *>(data);
93 thread->thread_entry();
98 WorkQueue::WorkQueue(void) :
99 busy(false), exit_workqueue(false)
103 err = pthread_create(&handle, NULL, WorkQueue__entry_thunk, this);
107 WorkQueue::~WorkQueue(void)
109 pthread_join(handle, NULL);