| 190 | } |
| 191 | |
| 192 | void CPUEngine::processQueue() |
| 193 | { |
| 194 | for (; ;) |
| 195 | { |
| 196 | Task task; |
| 197 | |
| 198 | // Wait until a task is available in the queue |
| 199 | { |
| 200 | std::unique_lock<std::mutex> lock(queueMutex); |
| 201 | queueCond.wait(lock, [&] { return !queue.empty() || queueShutdown; }); |
| 202 | if (queue.empty() && queueShutdown) |
| 203 | return; |
| 204 | task = std::move(queue.front()); |
| 205 | } |
| 206 | |
| 207 | // Execute queued tasks in the arena until the queue gets empty |
| 208 | arena->execute([&] |
| 209 | { |
| 210 | for (; ;) |
| 211 | { |
| 212 | if (task.ct && task.ct->isCancelled()) |
| 213 | device->setAsyncError(Error::Cancelled, "execution was cancelled"); |
| 214 | else |
| 215 | task.func(); |
| 216 | |
| 217 | task = {}; |
| 218 | |
| 219 | { |
| 220 | std::lock_guard<std::mutex> lock(queueMutex); |
| 221 | queue.pop(); |
| 222 | if (queue.empty()) |
| 223 | break; |
| 224 | task = std::move(queue.front()); |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | queueCond.notify_all(); |
| 229 | }); |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | OIDN_NAMESPACE_END |
nothing calls this directly
no test coverage detected