| 55 | } |
| 56 | |
| 57 | void Thread::Dispatch() { |
| 58 | { |
| 59 | std::unique_lock<std::mutex> ul(mutex_); |
| 60 | |
| 61 | // If we're still processing a previous dispatch, don't try to process another |
| 62 | if (processing_.load()) return; |
| 63 | |
| 64 | // If nothing to process, return early |
| 65 | if (frontQueue_.size() == 0) return; |
| 66 | |
| 67 | // Copy contents of front buffer to back buffer for processing |
| 68 | for (const auto & func : frontQueue_) backQueue_.push_back(func); |
| 69 | frontQueue_.clear(); |
| 70 | |
| 71 | // Signal ready for processing |
| 72 | processing_.store(true); |
| 73 | } |
| 74 | |
| 75 | // If we don't own the context, use the current thread |
| 76 | if (!ownsExecutionContext_) { |
| 77 | SetCurrentThread(this); |
| 78 | ProcessNext_(); |
| 79 | NullifyCurrentThread(); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | void Thread::DispatchAndSynchronize() { |
| 84 | Dispatch(); |
no test coverage detected