| 125 | } |
| 126 | |
| 127 | std::shared_ptr<XQueueWaitAllCommand> CommandBuffer::EnqueueXQueueWaitAllCommand() |
| 128 | { |
| 129 | std::unique_lock<std::mutex> lock(mtx_); |
| 130 | |
| 131 | if (xq_state_ == kQueueStateIdle) { |
| 132 | // If the XQueue is idle, syncing on this XQueue should return. Here, we should return |
| 133 | // a completed XCommand so that syncing on this XQueue will return immediately. |
| 134 | auto wait_all_cmd = std::dynamic_pointer_cast<XQueueWaitAllCommand>(last_enqueued_cmd_); |
| 135 | XASSERT(last_enqueued_cmd_->GetType() == kCommandTypeXQueueWaitAll && |
| 136 | wait_all_cmd != nullptr, |
| 137 | "last_enqueued_cmd_ must be an XQueueWaitAllCommand if the XQueue is idle"); |
| 138 | return wait_all_cmd; |
| 139 | } |
| 140 | |
| 141 | if (last_enqueued_cmd_->GetType() == kCommandTypeXQueueWaitAll) { |
| 142 | auto wait_all_cmd = std::dynamic_pointer_cast<XQueueWaitAllCommand>(last_enqueued_cmd_); |
| 143 | XASSERT(wait_all_cmd != nullptr, "last_enqueued_cmd_ must be an XQueueWaitAllCommand"); |
| 144 | return wait_all_cmd; |
| 145 | } |
| 146 | |
| 147 | auto xcmd = std::make_shared<XQueueWaitAllCommand>(); |
| 148 | xcmd->SetState(kCommandStatePending); |
| 149 | last_enqueued_cmd_ = xcmd; |
| 150 | cmds_.emplace_back(xcmd); |
| 151 | |
| 152 | lock.unlock(); |
| 153 | cv_.notify_all(); |
| 154 | return xcmd; |
| 155 | } |
no test coverage detected