| 37 | } |
| 38 | |
| 39 | std::shared_ptr<XCommand> CommandBuffer::Dequeue() |
| 40 | { |
| 41 | std::unique_lock<std::mutex> lock(mtx_); |
| 42 | |
| 43 | if (!cmds_.empty()) { |
| 44 | auto xcmd = cmds_.front(); |
| 45 | cmds_.pop_front(); |
| 46 | last_dequeued_cmd_ = xcmd; |
| 47 | XDEBG("xcmd (%p) dequeued from cmd buf (%p)", xcmd.get(), this); |
| 48 | return xcmd; |
| 49 | } |
| 50 | |
| 51 | XDEBG("cmd buf (%p) emptied, last_enqueued_cmd_ (%p), type (%d)", |
| 52 | this, last_enqueued_cmd_.get(), last_enqueued_cmd_->GetType()); |
| 53 | switch (last_enqueued_cmd_->GetType()) |
| 54 | { |
| 55 | case kCommandTypeXQueueWaitAll: |
| 56 | { |
| 57 | if (xq_state_ == kQueueStateReady) { |
| 58 | xq_state_ = kQueueStateIdle; |
| 59 | idle_cnt_++; |
| 60 | idle_cv_.notify_all(); |
| 61 | SchedAgent::SendEvent(std::make_shared<XQueueIdleEvent>(kXQueueHandle)); |
| 62 | } |
| 63 | |
| 64 | while (cmds_.empty()) cv_.wait(lock); |
| 65 | auto xcmd = cmds_.front(); |
| 66 | cmds_.pop_front(); |
| 67 | last_dequeued_cmd_ = xcmd; |
| 68 | XDEBG("xcmd (%p) dequeued from cmd buf (%p)", xcmd.get(), this); |
| 69 | return xcmd; |
| 70 | } |
| 71 | |
| 72 | case kCommandTypeBatchSynchronize: |
| 73 | { |
| 74 | auto xcmd = std::make_shared<XQueueWaitAllCommand>(); |
| 75 | xcmd->SetState(kCommandStatePending); |
| 76 | last_enqueued_cmd_ = xcmd; |
| 77 | last_dequeued_cmd_ = xcmd; |
| 78 | XDEBG("generated XQueueWaitAllCommand (%p) dequeued from cmd buf (%p)", xcmd.get(), this); |
| 79 | return xcmd; |
| 80 | } |
| 81 | |
| 82 | default: |
| 83 | { |
| 84 | auto xcmd = std::make_shared<BatchSynchronizeCommand>(); |
| 85 | xcmd->SetState(kCommandStatePending); |
| 86 | last_enqueued_cmd_ = xcmd; |
| 87 | last_dequeued_cmd_ = xcmd; |
| 88 | XDEBG("generated BatchSynchronizeCommand (%p) dequeued from cmd buf (%p)", |
| 89 | xcmd.get(), this); |
| 90 | return xcmd; |
| 91 | } |
| 92 | |
| 93 | } |
| 94 | |
| 95 | XASSERT(false, "should not reach here"); |
| 96 | return nullptr; |
no test coverage detected