diff options
Diffstat (limited to 'utils/src/Threaded.cpp')
-rw-r--r-- | utils/src/Threaded.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/utils/src/Threaded.cpp b/utils/src/Threaded.cpp index ee393a29..7e404f1d 100644 --- a/utils/src/Threaded.cpp +++ b/utils/src/Threaded.cpp @@ -21,14 +21,20 @@ void *Threaded::sThreadProc(void *p) Threaded *it = (Threaded *)p; void *result = it->ThreadProc(); - std::lock_guard<std::mutex> lock(it->_trd_mtx); - it->_trd_exited = true; - it->_trd_cond.notify_all(); + { + std::lock_guard<std::mutex> lock(it->_trd_mtx); + it->_trd_exited = true; + it->_trd_cond.notify_all(); + } + + if (it->_self_destruct) { + delete it; + } return result; } -bool Threaded::StartThread() +bool Threaded::StartThread(bool self_destruct) { std::lock_guard<std::mutex> lock(_trd_mtx); if (!_trd_joined) { @@ -41,6 +47,7 @@ bool Threaded::StartThread() } _trd_joined = _trd_exited = false; + _self_destruct = self_destruct; if (pthread_create(&_trd, NULL, &sThreadProc, this) != 0) { _trd_joined = _trd_exited = true; _trd = 0; |