diff --git a/hipamd/src/hip_event.cpp b/hipamd/src/hip_event.cpp index 3fff536439..265bd18ee9 100644 --- a/hipamd/src/hip_event.cpp +++ b/hipamd/src/hip_event.cpp @@ -27,6 +27,9 @@ namespace hip { +static amd::Monitor eventSetLock{"Guards global event set"}; +static std::unordered_set eventSet; + bool Event::ready() { if (event_->status() != CL_COMPLETE) { event_->notifyCmdQueue(); @@ -280,6 +283,8 @@ hipError_t ihipEventCreateWithFlags(hipEvent_t* event, unsigned flags) { return hipErrorOutOfMemory; } *event = reinterpret_cast(e); + amd::ScopedLock lock(hip::eventSetLock); + hip::eventSet.insert(*event); } else { return hipErrorInvalidValue; } @@ -313,6 +318,11 @@ hipError_t hipEventDestroy(hipEvent_t event) { HIP_RETURN(hipErrorInvalidHandle); } + amd::ScopedLock lock(hip::eventSetLock); + if (hip::eventSet.erase(event) == 0 ) { + return hipErrorContextIsDestroyed; + } + hip::Event* e = reinterpret_cast(event); delete e; HIP_RETURN(hipSuccess);