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.h33
1 files changed, 16 insertions, 17 deletions
diff --git a/src/common/spinlock.h b/src/common/spinlock.h
index 29fbb355b..bde36b8e5 100644
--- a/src/common/spinlock.h
+++ b/src/common/spinlock.h
@@ -1,11 +1,10 @@
-#pragma once
-#ifndef _COMMON_SPINLOCK_H_
-#define _COMMON_SPINLOCK_H_
+#ifndef COMMON_SPINLOCK_H
+#define COMMON_SPINLOCK_H
//
// CAS based Spinlock Implementation
//
-// CamelCase names are choosen to be consistent with microsofts winapi
+// CamelCase names are chosen to be consistent with Microsoft's WinAPI
// which implements CriticalSection by this naming...
//
// Author: Florian Wilkemeyer <fw@f-ws.de>
@@ -15,39 +14,39 @@
//
//
+#include "../common/atomic.h"
+#include "../common/cbasetypes.h"
+#include "../common/thread.h"
+
#ifdef WIN32
#include "../common/winapi.h"
#endif
-#include "../common/cbasetypes.h"
-#include "../common/atomic.h"
-#include "../common/thread.h"
-
#ifdef WIN32
typedef struct __declspec( align(64) ) SPIN_LOCK{
volatile LONG lock;
volatile LONG nest;
volatile LONG sync_lock;
-} SPIN_LOCK, *PSPIN_LOCK;
+} SPIN_LOCK;
#else
typedef struct SPIN_LOCK{
volatile int32 lock;
volatile int32 nest; // nesting level.
volatile int32 sync_lock;
-} __attribute__((aligned(64))) SPIN_LOCK, *PSPIN_LOCK;
+} __attribute__((aligned(64))) SPIN_LOCK;
#endif
-static forceinline void InitializeSpinLock(PSPIN_LOCK lck){
+static forceinline void InitializeSpinLock(SPIN_LOCK *lck){
lck->lock = 0;
lck->nest = 0;
lck->sync_lock = 0;
}
-static forceinline void FinalizeSpinLock(PSPIN_LOCK lck){
+static forceinline void FinalizeSpinLock(SPIN_LOCK *lck){
return;
}
@@ -55,10 +54,10 @@ static forceinline void FinalizeSpinLock(PSPIN_LOCK lck){
#define getsynclock(l) do { if(InterlockedCompareExchange((l), 1, 0) == 0) break; rathread_yield(); } while(/*always*/1)
#define dropsynclock(l) do { InterlockedExchange((l), 0); } while(0)
-static forceinline void EnterSpinLock(PSPIN_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.
+ // Get Sync Lock && Check if the requester thread already owns the lock.
// if it owns, increase nesting level
getsynclock(&lck->sync_lock);
if(InterlockedCompareExchange(&lck->lock, tid, tid) == tid){
@@ -70,7 +69,7 @@ static forceinline void EnterSpinLock(PSPIN_LOCK lck){
dropsynclock(&lck->sync_lock);
- // Spin until we've got it !
+ // Spin until we've got it !
while(1){
if(InterlockedCompareExchange(&lck->lock, tid, 0) == 0){
@@ -85,7 +84,7 @@ static forceinline void EnterSpinLock(PSPIN_LOCK lck){
}
-static forceinline void LeaveSpinLock(PSPIN_LOCK lck){
+static forceinline void LeaveSpinLock(SPIN_LOCK *lck){
int tid = rathread_get_tid();
getsynclock(&lck->sync_lock);
@@ -101,4 +100,4 @@ static forceinline void LeaveSpinLock(PSPIN_LOCK lck){
-#endif /* _COMMON_SPINLOCK_H_ */
+#endif /* COMMON_SPINLOCK_H */