Avoid lock for last queued command
Use atomics for last queued command update Change-Id: I759e9d78ea72f23c0d45dbede6250b231e122276
This commit is contained in:
1 parent
a811cfc567
commit
dc4e09a63a
2 files changed
+13
-13
No files matched your search
@@ -192,25 +192,27 @@ bool HostQueue::isEmpty() {
|
|||||||
|
|
||||||
void HostQueue::setLastQueuedCommand(Command* lastCommand) {
|
void HostQueue::setLastQueuedCommand(Command* lastCommand) {
|
||||||
// Set last submitted command
|
// Set last submitted command
|
||||||
ScopedLock l(lastCmdLock_);
|
Command* lastEnqueueCommand =
|
||||||
if (lastEnqueueCommand_ != nullptr) {
|
lastEnqueueCommand_.exchange(lastCommand, std::memory_order_acq_rel);
|
||||||
lastEnqueueCommand_->release();
|
if (lastEnqueueCommand != nullptr) {
|
||||||
|
lastEnqueueCommand->release();
|
||||||
}
|
}
|
||||||
lastEnqueueCommand_ = lastCommand;
|
|
||||||
if (lastCommand != nullptr) {
|
if (lastCommand != nullptr) {
|
||||||
lastEnqueueCommand_->retain();
|
lastCommand->retain();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Command* HostQueue::getLastQueuedCommand(bool retain) {
|
Command* HostQueue::getLastQueuedCommand(bool retain) {
|
||||||
// Get last submitted command
|
// Get last submitted command
|
||||||
ScopedLock l(lastCmdLock_);
|
Command* lastEnqueueCommand = lastEnqueueCommand_.load(std::memory_order_acquire);
|
||||||
|
if (lastEnqueueCommand == nullptr) {
|
||||||
if (retain && lastEnqueueCommand_ != nullptr) {
|
return nullptr;
|
||||||
lastEnqueueCommand_->retain();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return lastEnqueueCommand_;
|
if (retain) {
|
||||||
|
lastEnqueueCommand->retain();
|
||||||
|
}
|
||||||
|
return lastEnqueueCommand;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceQueue::~DeviceQueue() {
|
DeviceQueue::~DeviceQueue() {
|
||||||
|
|||||||
@@ -126,7 +126,6 @@ class CommandQueue : public RuntimeObject {
|
|||||||
rtCUs_(rtCUs),
|
rtCUs_(rtCUs),
|
||||||
priority_(priority),
|
priority_(priority),
|
||||||
queueLock_("CommandQueue::queueLock"),
|
queueLock_("CommandQueue::queueLock"),
|
||||||
lastCmdLock_("LastQueuedCommand"),
|
|
||||||
device_(device),
|
device_(device),
|
||||||
context_(context),
|
context_(context),
|
||||||
cuMask_(cuMask){}
|
cuMask_(cuMask){}
|
||||||
@@ -135,7 +134,6 @@ class CommandQueue : public RuntimeObject {
|
|||||||
uint rtCUs_; //!< The number of used RT compute units
|
uint rtCUs_; //!< The number of used RT compute units
|
||||||
Priority priority_; //!< Queue priority
|
Priority priority_; //!< Queue priority
|
||||||
Monitor queueLock_; //!< Lock protecting the queue
|
Monitor queueLock_; //!< Lock protecting the queue
|
||||||
Monitor lastCmdLock_; //!< Lock protecting the last queued command
|
|
||||||
Device& device_; //!< The device
|
Device& device_; //!< The device
|
||||||
SharedReference<Context> context_; //!< The context of this command queue
|
SharedReference<Context> context_; //!< The context of this command queue
|
||||||
const std::vector<uint32_t>& cuMask_; //!< The CU mask
|
const std::vector<uint32_t>& cuMask_; //!< The CU mask
|
||||||
@@ -187,7 +185,7 @@ class HostQueue : public CommandQueue {
|
|||||||
private:
|
private:
|
||||||
ConcurrentLinkedQueue<Command*> queue_; //!< The queue.
|
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.
|
//! Await commands and execute them as they become ready.
|
||||||
void loop(device::VirtualDevice* virtualDevice);
|
void loop(device::VirtualDevice* virtualDevice);
|
||||||
|
|||||||
Reference in new issue
Block a user