P4 to Git Change 1551367 by lmoriche@lmoriche_opencl_dev2 on 2018/05/07 18:40:02

SWDEV-145570 - [HIP] - Fix a race condition in the CommandQueue::Thread destruction.

Affected files ...

... //depot/stg/opencl/drivers/opencl/runtime/os/os_posix.cpp#44 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/commandqueue.cpp#26 edit


[ROCm/clr commit: 7fe8b95168]
This commit is contained in:
foreman
2018-05-07 18:50:50 -04:00
parent 87e83ca8a5
commit c6ba32fc41
2 changed files with 21 additions and 3 deletions
+3 -1
View File
@@ -390,7 +390,9 @@ void* Thread::entry(Thread* thread) {
return thread->main();
}
bool Os::isThreadAlive(const Thread& thread) { return true; }
bool Os::isThreadAlive(const Thread& thread) {
return ::pthread_kill((pthread_t)thread.handle(), 0) == 0;
}
const void* Os::createOsThread(amd::Thread* thread) {
pthread_attr_t threadAttr;
@@ -31,9 +31,25 @@ HostQueue::HostQueue(Context& context, Device& device, cl_command_queue_properti
bool HostQueue::terminate() {
if (Os::isThreadAlive(thread_)) {
Command* marker = nullptr;
// Send a finish if the queue is still accepting commands.
{ ScopedLock sl(queueLock_);
if (thread_.acceptingCommands_) {
marker = new Marker(*this, false);
if (marker != nullptr) {
append(*marker);
queueLock_.notify();
}
}
}
if (marker != nullptr) {
marker->awaitCompletion();
marker->release();
}
// Wake-up the command loop, so it can exit
{
ScopedLock sl(queueLock_);
{ ScopedLock sl(queueLock_);
thread_.acceptingCommands_ = false;
queueLock_.notify();
}