diff --git a/src/util/scoped_timer.cpp b/src/util/scoped_timer.cpp index 93e170836..644c234c4 100644 --- a/src/util/scoped_timer.cpp +++ b/src/util/scoped_timer.cpp @@ -34,7 +34,7 @@ Revision History: #endif struct scoped_timer_state { - std::thread * m_thread { nullptr }; + std::thread m_thread; std::timed_mutex m_mutex; event_handler * eh; unsigned ms; @@ -82,9 +82,11 @@ private: public: imp(unsigned ms, event_handler * eh) { workers.lock(); + bool new_worker = false; if (available_workers.empty()) { workers.unlock(); s = new scoped_timer_state; + new_worker = true; ++num_workers; } else { @@ -96,8 +98,8 @@ public: s->eh = eh; s->m_mutex.lock(); s->work = 1; - if (!s->m_thread) { - s->m_thread = new std::thread(thread_func, s); + if (new_worker) { + s->m_thread = std::thread(thread_func, s); } else { s->cv.notify_one(); @@ -146,8 +148,7 @@ void scoped_timer::finalize() { for (auto w : cleanup_workers) { ++deleted; - w->m_thread->join(); - delete w->m_thread; + w->m_thread.join(); delete w; } }