diff --git a/src/util/scoped_timer.cpp b/src/util/scoped_timer.cpp index d9f116646..93e170836 100644 --- a/src/util/scoped_timer.cpp +++ b/src/util/scoped_timer.cpp @@ -29,6 +29,9 @@ Revision History: #include #include #include +#ifndef _WINDOWS +#include +#endif struct scoped_timer_state { std::thread * m_thread { nullptr }; @@ -119,6 +122,16 @@ scoped_timer::~scoped_timer() { dealloc(m_imp); } +void scoped_timer::initialize() { +#ifndef _WINDOWS + static bool pthread_atfork_set = false; + if (!pthread_atfork_set) { + pthread_atfork(finalize, nullptr, nullptr); + pthread_atfork_set = true; + } +#endif +} + void scoped_timer::finalize() { unsigned deleted = 0; while (deleted < num_workers) { @@ -138,4 +151,5 @@ void scoped_timer::finalize() { delete w; } } + num_workers = 0; } diff --git a/src/util/scoped_timer.h b/src/util/scoped_timer.h index f54cba558..95920b71f 100644 --- a/src/util/scoped_timer.h +++ b/src/util/scoped_timer.h @@ -26,5 +26,10 @@ class scoped_timer { public: scoped_timer(unsigned ms, event_handler * eh); ~scoped_timer(); + static void initialize(); static void finalize(); }; + +/* + ADD_INITIALIZER('scoped_timer::initialize();') +*/