From 0782acabb540d93dda983580ece30b48241f52ca Mon Sep 17 00:00:00 2001 From: Christophe Paquot Date: Wed, 27 May 2020 17:15:58 -0700 Subject: [PATCH] Use a dedicated lock for last queued command set/get Change-Id: If3d2144841c7863cf7afe2ca85aea62e0a3a33c7 --- rocclr/platform/commandqueue.cpp | 10 ++++------ rocclr/platform/commandqueue.hpp | 2 ++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/rocclr/platform/commandqueue.cpp b/rocclr/platform/commandqueue.cpp index 9d7f6b9884..4ab1a2de69 100644 --- a/rocclr/platform/commandqueue.cpp +++ b/rocclr/platform/commandqueue.cpp @@ -192,7 +192,7 @@ bool HostQueue::isEmpty() { void HostQueue::setLastQueuedCommand(Command* lastCommand) { // Set last submitted command - ScopedLock sl(queueLock_); + ScopedLock l(lastCmdLock_); if (lastEnqueueCommand_ != nullptr) { lastEnqueueCommand_->release(); } @@ -204,14 +204,12 @@ void HostQueue::setLastQueuedCommand(Command* lastCommand) { Command* HostQueue::getLastQueuedCommand(bool retain) { // Get last submitted command - ScopedLock sl(queueLock_); - if (lastEnqueueCommand_ == nullptr) { - return nullptr; - } + ScopedLock l(lastCmdLock_); - if (retain) { + if (retain && lastEnqueueCommand_ != nullptr) { lastEnqueueCommand_->retain(); } + return lastEnqueueCommand_; } diff --git a/rocclr/platform/commandqueue.hpp b/rocclr/platform/commandqueue.hpp index 9a58a68578..e051bdecd8 100644 --- a/rocclr/platform/commandqueue.hpp +++ b/rocclr/platform/commandqueue.hpp @@ -126,6 +126,7 @@ class CommandQueue : public RuntimeObject { rtCUs_(rtCUs), priority_(priority), queueLock_("CommandQueue::queueLock"), + lastCmdLock_("LastQueuedCommand"), device_(device), context_(context), cuMask_(cuMask){} @@ -134,6 +135,7 @@ class CommandQueue : public RuntimeObject { uint rtCUs_; //!< The number of used RT compute units Priority priority_; //!< Queue priority Monitor queueLock_; //!< Lock protecting the queue + Monitor lastCmdLock_; //!< Lock protecting the last queued command Device& device_; //!< The device SharedReference context_; //!< The context of this command queue const std::vector& cuMask_; //!< The CU mask