| 274 | } |
| 275 | |
| 276 | int JobQueue::finalize() SKR_NOEXCEPT |
| 277 | { |
| 278 | // Queue as many JobFinalizeItems as the number of worker threads to finish the worker threads. |
| 279 | // Since the worker thread that received JobFinalizeItem will always end without taking the next Job, |
| 280 | // This will terminate all worker threads. |
| 281 | skr::stl_vector<JobFinalizeItem> finalJobs; |
| 282 | finalJobs.reserve(thread_list.size()); |
| 283 | for (int i = 0; i < thread_list.size(); ++i) |
| 284 | { |
| 285 | finalJobs.emplace_back(); |
| 286 | enqueueCore(&finalJobs.back(), /*isEndJob=*/true); // Normal enqueue will fail after this point |
| 287 | } |
| 288 | |
| 289 | // wait for worker thread to finish。 |
| 290 | for (auto *pWorkerThread : thread_list) |
| 291 | { |
| 292 | pWorkerThread->join(); |
| 293 | |
| 294 | SkrDelete(pWorkerThread->get_function()); |
| 295 | SkrDelete(pWorkerThread); |
| 296 | } |
| 297 | thread_list.clear(); |
| 298 | |
| 299 | return ASYNC_RESULT_OK; |
| 300 | } |
| 301 | |
| 302 | int JobQueue::enqueue(JobItem* jobItem) SKR_NOEXCEPT |
| 303 | { |
no test coverage detected