| 263 | } |
| 264 | |
| 265 | std::unique_lock<MutexLock> LaunchWorker::SyncAllWithLock(std::unique_lock<MutexLock> lock) |
| 266 | { |
| 267 | while (true) { |
| 268 | // Wait if the worker is paused. |
| 269 | while (true) { |
| 270 | if (state_ == kWorkerStateRunning) { |
| 271 | break; |
| 272 | } else if (state_ == kWorkerStatePaused) { |
| 273 | cv_.wait(lock); |
| 274 | } else if (state_ == kWorkerStateTerminated) { |
| 275 | return lock; |
| 276 | } else { |
| 277 | XASSERT(false, "Invalid worker state"); |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | // If there is no in-flight HwCommands, then no need to sync. |
| 282 | if (cmd_log_.size() == 0) return lock; |
| 283 | |
| 284 | int64_t current_pause_cnt = pause_count_; |
| 285 | |
| 286 | lock.unlock(); |
| 287 | kHwq->Synchronize(); |
| 288 | lock.lock(); |
| 289 | |
| 290 | // Check if preemption happened during kHwq->Synchronize(). |
| 291 | if (current_pause_cnt == pause_count_) break; |
| 292 | } |
| 293 | |
| 294 | // Pop and delete all in-flight HwCommands. |
| 295 | sync_cmd_log_.clear(); |
| 296 | |
| 297 | for (auto hw_cmd : cmd_log_) hw_cmd->SetState(kCommandStateCompleted); |
| 298 | cmd_log_.clear(); |
| 299 | |
| 300 | return lock; |
| 301 | } |
| 302 | |
| 303 | std::unique_lock<MutexLock> LaunchWorker::SyncCmdWithLock(std::unique_lock<utils::MutexLock> lock, |
| 304 | std::shared_ptr<HwCommand> hw_cmd) |
nothing calls this directly
no test coverage detected