| 22 | // ---------------------------------------------------------------------------------------- |
| 23 | |
| 24 | timer_global_clock:: |
| 25 | ~timer_global_clock() |
| 26 | { |
| 27 | // The only time this destructor is called is when |
| 28 | // |
| 29 | // a) the process terminates |
| 30 | // b) the dynamic library(.so/.dll) is unloaded (could be a part of a)) |
| 31 | // |
| 32 | // in case of a) |
| 33 | // windows: the process termination is especially painful, since threads are killed |
| 34 | // before destructors of the process image .dll's are called. |
| 35 | // Thus, for the windows platform, there is no threads running, so the only thing |
| 36 | // to do here is just let the standard memberwise destructors run |
| 37 | // linux: it's ok to just signal shutdown and wait for the running thread, to exit |
| 38 | // |
| 39 | // in case of b) |
| 40 | // windows: |
| 41 | // if it's part of the termination process, a) applies |
| 42 | // if its part of user doing manual load_library/unload_library |
| 43 | // there is no (safe/robust)solution, but best practices are described here |
| 44 | // https://msdn.microsoft.com/en-us/library/windows/desktop/dn633971.aspx |
| 45 | // to support such a clean shutdown, you are required to make a call prior to |
| 46 | // unload dll, that shutdown all the threads in the contained dll. |
| 47 | // This could be done in this module by providing a global_delete_clock() |
| 48 | // |
| 49 | // linux: the destructor for linux will do it's usual job regardless. |
| 50 | // |
| 51 | |
| 52 | #ifndef _WIN32 |
| 53 | m.lock(); |
| 54 | shutdown = true; |
| 55 | s.signal(); |
| 56 | m.unlock(); |
| 57 | wait(); |
| 58 | #endif |
| 59 | } |
| 60 | |
| 61 | // ---------------------------------------------------------------------------------------- |
| 62 | |