Make append and setLastQueuedCommand atomic

Two threads can enqueue to the same HostQueue (HostQueue::enqueue)
and result in last queued command being the first one reachine queue_.enqueue

NOTE: Temporarly make setLastQueuedCommand empty function to pass the build

Change-Id: Id09c3a28d184986f52b2ec86a2f6a18c40df1f0b
Αυτή η υποβολή περιλαμβάνεται σε:
Christophe Paquot
2020-07-10 08:32:15 -07:00
υποβλήθηκε από Saleel Kudchadker
γονέας 453ea922a7
υποβολή 3d15a1e291
3 αρχεία άλλαξαν με 11 προσθήκες και 16 διαγραφές
@@ -258,9 +258,6 @@ void Command::enqueue() {
ClPrint(LOG_DEBUG, LOG_CMD, "command is enqueued: %p", this);
queue_->append(*this);
if (IS_HIP) {
queue_->setLastQueuedCommand(this);
}
queue_->flush();
if ((queue_->device().settings().waitCommand_ && (type_ != 0)) ||
((commandWaitBits_ & 0x2) != 0)) {
@@ -185,7 +185,17 @@ void HostQueue::append(Command& command) {
}
command.retain();
command.setStatus(CL_QUEUED);
ScopedLock l(lastCmdLock_);
queue_.enqueue(&command);
if (!IS_HIP) {
return;
}
// Set last submitted command
if (lastEnqueueCommand_ != nullptr) {
lastEnqueueCommand_->release();
}
lastEnqueueCommand_ = &command;
lastEnqueueCommand_->retain();
}
bool HostQueue::isEmpty() {
@@ -193,18 +203,6 @@ bool HostQueue::isEmpty() {
return queue_.empty();
}
void HostQueue::setLastQueuedCommand(Command* lastCommand) {
// Set last submitted command
ScopedLock l(lastCmdLock_);
if (lastEnqueueCommand_ != nullptr) {
lastEnqueueCommand_->release();
}
lastEnqueueCommand_ = lastCommand;
if (lastCommand != nullptr) {
lastEnqueueCommand_->retain();
}
}
Command* HostQueue::getLastQueuedCommand(bool retain) {
// Get last submitted command
ScopedLock l(lastCmdLock_);
@@ -236,7 +236,7 @@ class HostQueue : public CommandQueue {
Command* getLastQueuedCommand(bool retain);
//! Set last enqueued command
void setLastQueuedCommand(Command* lastCommand);
void setLastQueuedCommand(Command* lastCommand) {}
};