diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lanes.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/lanes.cpp b/src/lanes.cpp index 7dd626b..df57bb4 100644 --- a/src/lanes.cpp +++ b/src/lanes.cpp | |||
@@ -801,11 +801,11 @@ void signal_handler(int signal_) | |||
801 | 801 | ||
802 | // helper to have correct callstacks when crashing a Win32 running on 64 bits Windows | 802 | // helper to have correct callstacks when crashing a Win32 running on 64 bits Windows |
803 | // don't forget to toggle Debug/Exceptions/Win32 in visual Studio too! | 803 | // don't forget to toggle Debug/Exceptions/Win32 in visual Studio too! |
804 | static volatile long s_ecoc_initCount = 0; | 804 | static std::atomic_flag s_ecoc_initDone; |
805 | static volatile int s_ecoc_go_ahead = 0; | 805 | static std::atomic_flag s_ecoc_go_ahead; |
806 | static void EnableCrashingOnCrashes(void) | 806 | static void EnableCrashingOnCrashes(void) |
807 | { | 807 | { |
808 | if (InterlockedCompareExchange(&s_ecoc_initCount, 1, 0) == 0) { | 808 | if (!s_ecoc_initDone.test_and_set(std::memory_order_acquire)) { |
809 | using GetPolicy_t = BOOL(WINAPI *)(LPDWORD lpFlags); | 809 | using GetPolicy_t = BOOL(WINAPI *)(LPDWORD lpFlags); |
810 | using SetPolicy_t = BOOL(WINAPI *)(DWORD dwFlags); | 810 | using SetPolicy_t = BOOL(WINAPI *)(DWORD dwFlags); |
811 | const DWORD EXCEPTION_SWALLOWING = 0x1; | 811 | const DWORD EXCEPTION_SWALLOWING = 0x1; |
@@ -826,11 +826,12 @@ static void EnableCrashingOnCrashes(void) | |||
826 | // typedef void (* SignalHandlerPointer)( int); | 826 | // typedef void (* SignalHandlerPointer)( int); |
827 | /*SignalHandlerPointer previousHandler =*/signal(SIGABRT, signal_handler); | 827 | /*SignalHandlerPointer previousHandler =*/signal(SIGABRT, signal_handler); |
828 | 828 | ||
829 | s_ecoc_go_ahead = 1; // let others pass | 829 | // we are done, other threads waiting to initialize lanes can proceed |
830 | std::ignore = s_ecoc_go_ahead.test_and_set(std::memory_order_relaxed); | ||
831 | s_ecoc_go_ahead.notify_all(); | ||
830 | } else { | 832 | } else { |
831 | while (!s_ecoc_go_ahead) { | 833 | // wait until flag becomes true |
832 | Sleep(1); | 834 | s_ecoc_go_ahead.wait(false, std::memory_order_relaxed); |
833 | } // changes threads | ||
834 | } | 835 | } |
835 | } | 836 | } |
836 | #endif // PLATFORM_WIN32 && !defined NDEBUG | 837 | #endif // PLATFORM_WIN32 && !defined NDEBUG |