Avoid lock for last queued command
Use atomics for last queued command update Change-Id: I759e9d78ea72f23c0d45dbede6250b231e122276
This commit is contained in:
@@ -192,25 +192,27 @@ bool HostQueue::isEmpty() {
|
||||
|
||||
void HostQueue::setLastQueuedCommand(Command* lastCommand) {
|
||||
// Set last submitted command
|
||||
ScopedLock l(lastCmdLock_);
|
||||
if (lastEnqueueCommand_ != nullptr) {
|
||||
lastEnqueueCommand_->release();
|
||||
Command* lastEnqueueCommand =
|
||||
lastEnqueueCommand_.exchange(lastCommand, std::memory_order_acq_rel);
|
||||
if (lastEnqueueCommand != nullptr) {
|
||||
lastEnqueueCommand->release();
|
||||
}
|
||||
lastEnqueueCommand_ = lastCommand;
|
||||
if (lastCommand != nullptr) {
|
||||
lastEnqueueCommand_->retain();
|
||||
lastCommand->retain();
|
||||
}
|
||||
}
|
||||
|
||||
Command* HostQueue::getLastQueuedCommand(bool retain) {
|
||||
// Get last submitted command
|
||||
ScopedLock l(lastCmdLock_);
|
||||
|
||||
if (retain && lastEnqueueCommand_ != nullptr) {
|
||||
lastEnqueueCommand_->retain();
|
||||
Command* lastEnqueueCommand = lastEnqueueCommand_.load(std::memory_order_acquire);
|
||||
if (lastEnqueueCommand == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return lastEnqueueCommand_;
|
||||
if (retain) {
|
||||
lastEnqueueCommand->retain();
|
||||
}
|
||||
return lastEnqueueCommand;
|
||||
}
|
||||
|
||||
DeviceQueue::~DeviceQueue() {
|
||||
|
||||
@@ -126,7 +126,6 @@ class CommandQueue : public RuntimeObject {
|
||||
rtCUs_(rtCUs),
|
||||
priority_(priority),
|
||||
queueLock_("CommandQueue::queueLock"),
|
||||
lastCmdLock_("LastQueuedCommand"),
|
||||
device_(device),
|
||||
context_(context),
|
||||
cuMask_(cuMask){}
|
||||
@@ -135,7 +134,6 @@ 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> context_; //!< The context of this command queue
|
||||
const std::vector<uint32_t>& cuMask_; //!< The CU mask
|
||||
@@ -187,7 +185,7 @@ class HostQueue : public CommandQueue {
|
||||
private:
|
||||
ConcurrentLinkedQueue<Command*> queue_; //!< The queue.
|
||||
|
||||
Command* lastEnqueueCommand_; //!< The last submitted command
|
||||
std::atomic<Command*> lastEnqueueCommand_; //!< The last submitted command
|
||||
|
||||
//! Await commands and execute them as they become ready.
|
||||
void loop(device::VirtualDevice* virtualDevice);
|
||||
|
||||
Reference in New Issue
Block a user