From d3a9985f101aa45972eafe943e68eef70efc5e3d Mon Sep 17 00:00:00 2001 From: Siu Chi Chan Date: Sat, 2 Jun 2018 17:55:37 -0400 Subject: [PATCH 1/2] callback handler: don't need to wait for the thread to become ready --- src/hip_stream.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/hip_stream.cpp b/src/hip_stream.cpp index d9c227b6ac..4170e33d63 100644 --- a/src/hip_stream.cpp +++ b/src/hip_stream.cpp @@ -201,14 +201,5 @@ hipError_t hipStreamAddCallback(hipStream_t stream, hipStreamCallback_t callback ihipStreamCallback_t* cb = new ihipStreamCallback_t(stream, callback, userData); std::thread(ihipStreamCallbackHandler, cb).detach(); - // Wait for thread to be ready - cb->_mtx.lock(); - while (cb->_ready != true) { - cb->_mtx.unlock(); - std::this_thread::sleep_for(std::chrono::milliseconds(10)); - cb->_mtx.lock(); - } - cb->_mtx.unlock(); - return ihipLogStatus(e); } From a1f3b587fb6c29b3217e2d3baac00448dc208f83 Mon Sep 17 00:00:00 2001 From: Siu Chi Chan Date: Mon, 4 Jun 2018 17:29:04 -0400 Subject: [PATCH 2/2] remove the _ready flag in ihipStreamCallback_t and the mutex that protects it. --- src/hip_hcc.cpp | 4 ---- src/hip_hcc_internal.h | 3 --- 2 files changed, 7 deletions(-) diff --git a/src/hip_hcc.cpp b/src/hip_hcc.cpp index 9856dc1905..538a9039bf 100644 --- a/src/hip_hcc.cpp +++ b/src/hip_hcc.cpp @@ -1445,10 +1445,6 @@ hipError_t ihipStreamSynchronize(hipStream_t stream) { void ihipStreamCallbackHandler(ihipStreamCallback_t* cb) { hipError_t e = hipSuccess; - // Notify hipStreamAddCallback that callback handler thread is active - std::lock_guard guard(cb->_mtx); - cb->_ready = true; - // Synchronize stream tprintf(DB_SYNC, "ihipStreamCallbackHandler wait on stream %s\n", ToString(cb->_stream).c_str()); diff --git a/src/hip_hcc_internal.h b/src/hip_hcc_internal.h index ce8041ef63..4008df1574 100644 --- a/src/hip_hcc_internal.h +++ b/src/hip_hcc_internal.h @@ -620,13 +620,10 @@ class ihipStreamCallback_t { public: ihipStreamCallback_t(hipStream_t stream, hipStreamCallback_t callback, void* userData) : _stream(stream), _callback(callback), _userData(userData) { - _ready = false; }; hipStream_t _stream; hipStreamCallback_t _callback; void* _userData; - std::mutex _mtx; - bool _ready; };