Merge pull request #491 from scchan/fix_wait
callback handling: don't need to wait for the thread to become ready
[ROCm/clr commit: f7c49dde38]
This commit is contained in:
@@ -1452,10 +1452,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<std::mutex> guard(cb->_mtx);
|
||||
cb->_ready = true;
|
||||
|
||||
// Synchronize stream
|
||||
tprintf(DB_SYNC, "ihipStreamCallbackHandler wait on stream %s\n",
|
||||
ToString(cb->_stream).c_str());
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user