From 44bc0cb35d91bf433e839f58205a186e6a0986cc Mon Sep 17 00:00:00 2001 From: German Andryeyev Date: Thu, 4 Jun 2020 15:17:45 -0400 Subject: [PATCH] Revert "Avoid lock for last queued command" This reverts commit dc4e09a63a6823a3e661f73307bbca080dab4ac6. Reason for revert: Change-Id: Ie10442c9447f010bb90c679b6cffca5b48b8d054 --- rocclr/platform/commandqueue.cpp | 22 ++++++++++------------ rocclr/platform/commandqueue.hpp | 4 +++- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/rocclr/platform/commandqueue.cpp b/rocclr/platform/commandqueue.cpp index ac17d90f86..4ab1a2de69 100644 --- a/rocclr/platform/commandqueue.cpp +++ b/rocclr/platform/commandqueue.cpp @@ -192,27 +192,25 @@ bool HostQueue::isEmpty() { void HostQueue::setLastQueuedCommand(Command* lastCommand) { // Set last submitted command - Command* lastEnqueueCommand = - lastEnqueueCommand_.exchange(lastCommand, std::memory_order_acq_rel); - if (lastEnqueueCommand != nullptr) { - lastEnqueueCommand->release(); + ScopedLock l(lastCmdLock_); + if (lastEnqueueCommand_ != nullptr) { + lastEnqueueCommand_->release(); } + lastEnqueueCommand_ = lastCommand; if (lastCommand != nullptr) { - lastCommand->retain(); + lastEnqueueCommand_->retain(); } } Command* HostQueue::getLastQueuedCommand(bool retain) { // Get last submitted command - Command* lastEnqueueCommand = lastEnqueueCommand_.load(std::memory_order_acquire); - if (lastEnqueueCommand == nullptr) { - return nullptr; + ScopedLock l(lastCmdLock_); + + if (retain && lastEnqueueCommand_ != nullptr) { + lastEnqueueCommand_->retain(); } - if (retain) { - lastEnqueueCommand->retain(); - } - return lastEnqueueCommand; + return lastEnqueueCommand_; } DeviceQueue::~DeviceQueue() { diff --git a/rocclr/platform/commandqueue.hpp b/rocclr/platform/commandqueue.hpp index a5d22ede02..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 @@ -185,7 +187,7 @@ class HostQueue : public CommandQueue { private: ConcurrentLinkedQueue queue_; //!< The queue. - std::atomic lastEnqueueCommand_; //!< The last submitted command + Command* lastEnqueueCommand_; //!< The last submitted command //! Await commands and execute them as they become ready. void loop(device::VirtualDevice* virtualDevice);