| 241 | } |
| 242 | |
| 243 | void HostQueue::loop(device::VirtualDevice* virtualDevice) { |
| 244 | // Notify the caller that the queue is ready to accept commands. |
| 245 | { |
| 246 | ScopedLock sl(queueLock_); |
| 247 | // Notify HostQueue() that acceptingCommands_ is updated to true |
| 248 | thread_.acceptingCommands_ = true; |
| 249 | queueLock_.notify(); |
| 250 | } |
| 251 | // Create a command batch with all the commands present in the queue. |
| 252 | Command* head = NULL; |
| 253 | Command* tail = NULL; |
| 254 | while (true) { |
| 255 | // Get one command from the queue |
| 256 | Command* command = queue_.dequeue(); |
| 257 | if (command == NULL) { |
| 258 | ScopedLock sl(queueLock_); |
| 259 | while ((command = queue_.dequeue()) == NULL) { |
| 260 | if (!thread_.acceptingCommands_) { |
| 261 | return; |
| 262 | } |
| 263 | queueLock_.wait(); |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | command->retain(); |
| 268 | |
| 269 | // Process the command's event wait list. |
| 270 | const Command::EventWaitList& events = command->eventWaitList(); |
| 271 | bool dependencyFailed = false; |
| 272 | ClPrint(LOG_DETAIL_DEBUG, LOG_CMD, "Command (%s) processing: %p ,events.size(): %d", |
| 273 | amd::activity_prof::getOclCommandKindString(command->type()), command, events.size()); |
| 274 | for (const auto& it : events) { |
| 275 | // Only wait if the command is enqueued into another queue. |
| 276 | if (it->command().queue() != this) { |
| 277 | // Runtime has to flush the current batch only if the dependent wait is blocking |
| 278 | if (it->command().status() != CL_COMPLETE) { |
| 279 | ClPrint(LOG_DETAIL_DEBUG, LOG_CMD, "Command (%s) %p awaiting event: %p", |
| 280 | amd::activity_prof::getOclCommandKindString(command->type()), command, it); |
| 281 | virtualDevice->flush(head, true); |
| 282 | tail = head = NULL; |
| 283 | dependencyFailed |= !it->awaitCompletion(); |
| 284 | } |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | // Insert the command to the linked list. |
| 289 | if (NULL == head) { // if the list is empty |
| 290 | head = tail = command; |
| 291 | } else { |
| 292 | tail->setNext(command); |
| 293 | tail = command; |
| 294 | } |
| 295 | |
| 296 | if (dependencyFailed) { |
| 297 | command->setStatus(CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST); |
| 298 | continue; |
| 299 | } |
| 300 |
no test coverage detected