| 315 | } |
| 316 | |
| 317 | void HostQueue::append(Command& command) { |
| 318 | // We retain the command here. It will be released when its status |
| 319 | // changes to CL_COMPLETE |
| 320 | if ((command.getWaitBits() & 0x1) != 0) { |
| 321 | finish(); |
| 322 | } |
| 323 | command.retain(); |
| 324 | command.setStatus(CL_QUEUED); |
| 325 | queue_.enqueue(&command); |
| 326 | if (!IS_HIP) { |
| 327 | return; |
| 328 | } |
| 329 | |
| 330 | // Set last submitted command |
| 331 | Command* prevLastEnqueueCommand = nullptr; |
| 332 | |
| 333 | // Attach only real commands and skip internal notifications for CPU queue |
| 334 | if (command.waitingEvent() == nullptr) { |
| 335 | command.retain(); |
| 336 | |
| 337 | // lastCmdLock_ ensures that lastEnqueueCommand() can retain the command before it is swapped |
| 338 | // out. We want to keep this critical section as short as possible, so the command should be |
| 339 | // released outside this section. |
| 340 | ScopedLock l(lastCmdLock_); |
| 341 | |
| 342 | prevLastEnqueueCommand = lastEnqueueCommand_; |
| 343 | lastEnqueueCommand_ = &command; |
| 344 | } |
| 345 | |
| 346 | if (prevLastEnqueueCommand != nullptr) { |
| 347 | prevLastEnqueueCommand->release(); |
| 348 | } else { |
| 349 | // The queue becomes active. Add it to the set of activeQueues. |
| 350 | device_.addToActiveQueues(this); |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | bool HostQueue::isEmpty() { |
| 355 | // Get a snapshot of queue size |