try to add a job to the queue if the queue is not too large
| 2107 | |
| 2108 | // try to add a job to the queue if the queue is not too large |
| 2109 | bool try_enqueue(const char *pathname, uint16_t cost, size_t slot) |
| 2110 | { |
| 2111 | Job *job = tail.load(); |
| 2112 | Job *next = job + 1; |
| 2113 | if (next == &ring[DEFAULT_MAX_JOB_QUEUE_SIZE]) |
| 2114 | next = ring; |
| 2115 | |
| 2116 | if (next == head.load()) |
| 2117 | return false; |
| 2118 | |
| 2119 | job->pathname.assign(pathname); |
| 2120 | job->cost = cost; |
| 2121 | job->slot = slot; |
| 2122 | tail.store(next); |
| 2123 | ++todo; |
| 2124 | queue_data.notify_one(); |
| 2125 | |
| 2126 | return true; |
| 2127 | } |
| 2128 | |
| 2129 | // pop a job |
| 2130 | void dequeue(Job& job) |