@@ -47,6 +47,14 @@ namespace
4747
4848 return res;
4949 }
50+
51+ template <class T >
52+ bool atomic_compare_exchange_strong_discard (std::atomic<T>* obj, typename std::atomic<T>::value_type expected, typename std::atomic<T>::value_type desired)
53+ {
54+ typename std::atomic<T>::value_type v{ expected };
55+
56+ return obj->compare_exchange_strong (v, desired);
57+ }
5058}
5159
5260static bool sgIsCollecting = false ;
@@ -874,8 +882,7 @@ struct BlockDataInfo
874882 if (mZeroed )
875883 return false ;
876884
877- int expected{ 0 };
878- if (mZeroLock .compare_exchange_strong (expected, 1 ))
885+ if (atomic_compare_exchange_strong_discard (&mZeroLock , 0 , 1 ))
879886 return zeroAndUnlock ();
880887
881888 return false ;
@@ -1648,8 +1655,7 @@ struct GlobalChunks
16481655 if (inChunk)
16491656 release (inChunk);
16501657
1651- int expected{ 0 };
1652- while (false == processListPopLock.compare_exchange_strong (expected, 1 ))
1658+ while (false == atomic_compare_exchange_strong_discard (&processListPopLock, 0 , 1 ))
16531659 {
16541660 // Spin
16551661 #ifdef PROFILE_THREAD_USAGE
@@ -1732,8 +1738,7 @@ struct GlobalChunks
17321738
17331739 inline MarkChunk *alloc ()
17341740 {
1735- int expected{ 0 };
1736- while (false == freeListPopLock.compare_exchange_strong (expected, 1 ))
1741+ while (false == atomic_compare_exchange_strong_discard (&freeListPopLock, 0 , 1 ))
17371742 {
17381743 // Spin
17391744 #ifdef PROFILE_THREAD_USAGE
@@ -3386,8 +3391,7 @@ class GlobalAllocator
33863391 if (!info->mOwned && info->mMaxHoleSize >=inRequiredBytes)
33873392 {
33883393 // Acquire the zero-lock
3389- int expected{ 0 };
3390- if (info->mZeroLock .compare_exchange_strong (expected, 1 ))
3394+ if (atomic_compare_exchange_strong_discard (&info->mZeroLock , 0 , 1 ))
33913395 {
33923396 // Acquire ownership...
33933397 if (info->mOwned )
@@ -4823,8 +4827,7 @@ class GlobalAllocator
48234827 #ifndef HXCPP_SINGLE_THREADED_APP
48244828 // If we set the flag from 0 -> 0xffffffff then we are the collector
48254829 // otherwise, someone else is collecting at the moment - so wait...
4826- unsigned int expected{ 0 };
4827- if (false == hx::gPauseForCollect .compare_exchange_strong (expected, std::numeric_limits<unsigned int >::max ()))
4830+ if (false == atomic_compare_exchange_strong_discard (&hx::gPauseForCollect , 0 , std::numeric_limits<unsigned int >::max ()))
48284831 {
48294832 if (inLocked)
48304833 {
0 commit comments