From 59f2a57563b7488779a9b93220a9dfe5c6a45700 Mon Sep 17 00:00:00 2001 From: Steve MacLean Date: Thu, 6 Jul 2017 23:59:49 +0000 Subject: GC Prefer CompareExchange --- src/gc/gc.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/gc/gc.cpp b/src/gc/gc.cpp index 4ba4b66c92..5afc024090 100644 --- a/src/gc/gc.cpp +++ b/src/gc/gc.cpp @@ -831,7 +831,7 @@ respin: return TRUE; } - if (Interlocked::Decrement(&join_struct.r_join_lock) != (join_struct.n_threads - 1)) + if (Interlocked::CompareExchange(&join_struct.r_join_lock, 0, join_struct.n_threads) == 0) { if (!join_struct.wait_done) { @@ -1083,7 +1083,7 @@ public: { dprintf (3, ("cm: probing %Ix", obj)); retry: - if (Interlocked::Exchange (&needs_checking, 1) == 0) + if (Interlocked::CompareExchange(&needs_checking, 1, 0) == 0) { // If we spend too much time spending all the allocs, // consider adding a high water mark and scan up @@ -1122,7 +1122,7 @@ retry: retry: dprintf (3, ("loh alloc: probing %Ix", obj)); - if (Interlocked::Exchange (&needs_checking, 1) == 0) + if (Interlocked::CompareExchange(&needs_checking, 1, 0) == 0) { if (obj == rwp_object) { @@ -1581,7 +1581,7 @@ static void enter_spin_lock_noinstru (RAW_KEYWORD(volatile) int32_t* lock) { retry: - if (Interlocked::Exchange (lock, 0) >= 0) + if (Interlocked::CompareExchange(lock, 0, -1) >= 0) { unsigned int i = 0; while (VolatileLoad(lock) >= 0) @@ -1623,7 +1623,7 @@ retry: inline static BOOL try_enter_spin_lock_noinstru(RAW_KEYWORD(volatile) int32_t* lock) { - return (Interlocked::Exchange (&*lock, 0) < 0); + return (Interlocked::CompareExchange(&*lock, 0, -1) < 0); } inline @@ -1742,7 +1742,7 @@ static void enter_spin_lock (GCSpinLock* spin_lock) { retry: - if (Interlocked::Exchange (&spin_lock->lock, 0) >= 0) + if (Interlocked::CompareExchange(&spin_lock->lock, 0, -1) >= 0) { unsigned int i = 0; while (spin_lock->lock >= 0) @@ -1793,7 +1793,7 @@ retry: inline BOOL try_enter_spin_lock(GCSpinLock* spin_lock) { - return (Interlocked::Exchange (&spin_lock->lock, 0) < 0); + return (Interlocked::CompareExchange(&spin_lock->lock, 0, -1) < 0); } inline @@ -10269,7 +10269,7 @@ gc_heap::enter_gc_done_event_lock() uint32_t dwSwitchCount = 0; retry: - if (Interlocked::Exchange (&gc_done_event_lock, 0) >= 0) + if (Interlocked::CompareExchange(&gc_done_event_lock, 0, -1) >= 0) { while (gc_done_event_lock >= 0) { @@ -35717,7 +35717,7 @@ void CFinalize::EnterFinalizeLock() GCToEEInterface::IsPreemptiveGCDisabled(GCToEEInterface::GetThread())); retry: - if (Interlocked::Exchange (&lock, 0) >= 0) + if (Interlocked::CompareExchange(&lock, 0, -1) >= 0) { unsigned int i = 0; while (lock >= 0) -- cgit v1.2.3