aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2024-11-13 09:34:04 +0100
committerBenoit Germain <benoit.germain@ubisoft.com>2024-11-13 09:34:04 +0100
commitd9879337c9843d7bcc936a6fbf0755288ed70607 (patch)
tree6c923809c5cbfe6842c9bed915414951a82c7a9e
parent3d2ee2a988cf59371945eedd3238c55f3452170a (diff)
downloadlanes-d9879337c9843d7bcc936a6fbf0755288ed70607.tar.gz
lanes-d9879337c9843d7bcc936a6fbf0755288ed70607.tar.bz2
lanes-d9879337c9843d7bcc936a6fbf0755288ed70607.zip
Cleaning up guano
Converted some volatile crap to std::atomic_flag in EnableCrashingOnCrashes
-rw-r--r--src/lanes.cpp15
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!
804static volatile long s_ecoc_initCount = 0; 804static std::atomic_flag s_ecoc_initDone;
805static volatile int s_ecoc_go_ahead = 0; 805static std::atomic_flag s_ecoc_go_ahead;
806static void EnableCrashingOnCrashes(void) 806static 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