pop a job
| 2128 | |
| 2129 | // pop a job |
| 2130 | void dequeue(Job& job) |
| 2131 | { |
| 2132 | while (empty()) |
| 2133 | { |
| 2134 | // we must lock and wait until the buffer is not empty |
| 2135 | std::unique_lock<std::mutex> lock(queue_mutex); |
| 2136 | queue_data.wait(lock); |
| 2137 | lock.unlock(); |
| 2138 | } |
| 2139 | |
| 2140 | Job *next = head.load() + 1; |
| 2141 | if (next == &ring[DEFAULT_MAX_JOB_QUEUE_SIZE]) |
| 2142 | next = ring; |
| 2143 | |
| 2144 | job = *head.load(); |
| 2145 | head.store(next); |
| 2146 | --todo; |
| 2147 | queue_full.notify_one(); |
| 2148 | } |
| 2149 | |
| 2150 | Job ring[DEFAULT_MAX_JOB_QUEUE_SIZE]; |
| 2151 | std::atomic<Job*> head; |