diff --git a/ixwebsocket/IXSocketServer.cpp b/ixwebsocket/IXSocketServer.cpp index 5d7512ba..c4ea1afb 100644 --- a/ixwebsocket/IXSocketServer.cpp +++ b/ixwebsocket/IXSocketServer.cpp @@ -219,6 +219,10 @@ namespace ix if (_gcThread.joinable()) { _stopGc = true; + { + std::lock_guard lock{ _conditionVariableMutexGC }; + _canContinueGC = true; + } _conditionVariableGC.notify_one(); _gcThread.join(); _stopGc = false; @@ -451,7 +455,10 @@ namespace ix if (!_stopGc) { std::unique_lock lock(_conditionVariableMutexGC); - _conditionVariableGC.wait(lock); + if(!_canContinueGC) { + _conditionVariableGC.wait(lock, [this]{ return _canContinueGC; }); + } + _canContinueGC = false; } } } @@ -465,6 +472,10 @@ namespace ix { // a connection got terminated, we can run the connection thread GC, // so wake up the thread responsible for that + { + std::lock_guard lock{ _conditionVariableMutexGC }; + _canContinueGC = true; + } _conditionVariableGC.notify_one(); } diff --git a/ixwebsocket/IXSocketServer.h b/ixwebsocket/IXSocketServer.h index fe0f7e28..c56b650e 100644 --- a/ixwebsocket/IXSocketServer.h +++ b/ixwebsocket/IXSocketServer.h @@ -126,5 +126,6 @@ namespace ix // as a connection std::condition_variable _conditionVariableGC; std::mutex _conditionVariableMutexGC; + bool _canContinueGC{ false }; }; } // namespace ix