summaryrefslogtreecommitdiff
path: root/src/common/spinlock.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/spinlock.h')
-rw-r--r--src/common/spinlock.h26
1 files changed, 11 insertions, 15 deletions
diff --git a/src/common/spinlock.h b/src/common/spinlock.h
index bde36b8e5..85a78ed33 100644
--- a/src/common/spinlock.h
+++ b/src/common/spinlock.h
@@ -13,7 +13,7 @@
// For more information, see LICENCE in the main folder
//
//
-
+
#include "../common/atomic.h"
#include "../common/cbasetypes.h"
#include "../common/thread.h"
@@ -33,7 +33,7 @@ typedef struct __declspec( align(64) ) SPIN_LOCK{
typedef struct SPIN_LOCK{
volatile int32 lock;
volatile int32 nest; // nesting level.
-
+
volatile int32 sync_lock;
} __attribute__((aligned(64))) SPIN_LOCK;
#endif
@@ -56,7 +56,7 @@ static forceinline void FinalizeSpinLock(SPIN_LOCK *lck){
static forceinline void EnterSpinLock(SPIN_LOCK *lck){
int tid = rathread_get_tid();
-
+
// Get Sync Lock && Check if the requester thread already owns the lock.
// if it owns, increase nesting level
getsynclock(&lck->sync_lock);
@@ -67,18 +67,14 @@ static forceinline void EnterSpinLock(SPIN_LOCK *lck){
}
// drop sync lock
dropsynclock(&lck->sync_lock);
-
-
+
// Spin until we've got it !
while(1){
-
- if(InterlockedCompareExchange(&lck->lock, tid, 0) == 0){
-
- InterlockedIncrement(&lck->nest);
- return; // Got Lock
- }
-
- rathread_yield(); // Force ctxswitch to another thread.
+ if(InterlockedCompareExchange(&lck->lock, tid, 0) == 0){
+ InterlockedIncrement(&lck->nest);
+ return; // Got Lock
+ }
+ rathread_yield(); // Force ctxswitch to another thread.
}
}
@@ -88,12 +84,12 @@ static forceinline void LeaveSpinLock(SPIN_LOCK *lck){
int tid = rathread_get_tid();
getsynclock(&lck->sync_lock);
-
+
if(InterlockedCompareExchange(&lck->lock, tid, tid) == tid){ // this thread owns the lock.
if(InterlockedDecrement(&lck->nest) == 0)
InterlockedExchange(&lck->lock, 0); // Unlock!
}
-
+
dropsynclock(&lck->sync_lock);
}