| 139 | } |
| 140 | |
| 141 | int Async::work(bx::Thread* thread, void* userData) { |
| 142 | DORA_UNUSED_PARAM(thread); |
| 143 | Async* worker = r_cast<Async*>(userData); |
| 144 | while (true) { |
| 145 | if (worker->isPoolWorker()) { |
| 146 | Async* source = nullptr; |
| 147 | Own<QEvent> event; |
| 148 | if (worker->_pool->popTask(worker->_poolIndex, source, event)) { |
| 149 | source->processWorkerEvent(std::move(event), source); |
| 150 | continue; |
| 151 | } |
| 152 | if (worker->_pool->isStopping()) { |
| 153 | return 0; |
| 154 | } |
| 155 | worker->_pool->waitForTask(); |
| 156 | continue; |
| 157 | } |
| 158 | for (auto event = worker->pollWorkerEvent(); |
| 159 | event != nullptr; |
| 160 | event = worker->pollWorkerEvent()) { |
| 161 | if (worker->processWorkerEvent(std::move(event), worker)) { |
| 162 | return 0; |
| 163 | } |
| 164 | } |
| 165 | if (worker->_stopped.load(std::memory_order_acquire)) { |
| 166 | return 0; |
| 167 | } |
| 168 | worker->_workerSemaphore.wait(); |
| 169 | } |
| 170 | return 0; |
| 171 | } |
| 172 | |
| 173 | void Async::cancel() { |
| 174 | for (auto event = _workerEvent.poll(); |
no test coverage detected