7 *******************************************************************************
9 * this is a Microsoft windows-based operating system. *
11 *******************************************************************************
13 # if defined(_WIN32) || defined(_WIN64)
15 # define pthread_attr_t HANDLE
16 # define pthread_t HANDLE
17 # define thread_t HANDLE
19 extern pthread_t NumaStartThread(void *func, void *args);
21 # if ((defined (_M_IA64) || defined (_M_AMD64)) && !defined(NT_INTEREX))
25 # pragma intrinsic (_InterlockedExchange)
27 typedef volatile LONG lock_t[1];
29 # define LockInit(v) ((v)[0] = 0)
30 # define LockFree(v) ((v)[0] = 0)
31 # define Unlock(v) ((v)[0] = 0)
33 __forceinline void Lock(volatile LONG * hPtr)
38 iValue = _InterlockedExchange((LPLONG) hPtr, 1);
45 # else /* NT non-Alpha/Intel, without assembler Lock() */
47 # define lock_t volatile int
48 # define LockInit(v) ((v) = 0)
49 # define LockFree(v) ((v) = 0)
50 # define Lock(v) do { \
51 while(InterlockedExchange((LPLONG)&(v),1) != 0); \
53 # define Unlock(v) ((v) = 0)
55 # endif /* architecture check */
59 *******************************************************************************
61 * this is a Unix-based operating system. define the spinlock code as needed *
62 * for SMP synchronization. *
64 *******************************************************************************
69 # include <machine/builtins.h>
71 # define lock_t volatile long
72 # define LockInit(v) ((v) = 0)
73 # define LockFree(v) ((v) = 0)
74 # define Lock(v) __LOCK_LONG(&(v))
75 # define Unlock(v) __UNLOCK_LONG(&(v))
77 # elif defined(POWERPC)
80 # include <libkern/OSAtomic.h>
82 # define lock_t OSSpinLock
83 # define LockInit(v) ((v) = 0)
84 # define LockFree(v) ((v) = 0)
85 # define Lock(v) OSSpinLockLock(&(v))
86 # define Unlock(v) OSSpinLockUnlock(&(v))
91 # define Pause() ({asm volatile ("pause");})
93 static void __inline__ LockX86(volatile int *lock)
96 asm __volatile__("1: movl $1, %0" "\n\t"
97 " xchgl (%1), %0" "\n\t" " testl %0, %0" "\n\t"
98 " jz 3f" "\n\t" "2: pause" "\n\t"
99 " movl (%1), %0" "\n\t" " testl %0, %0" "\n\t"
100 " jnz 2b" "\n\t" " jmp 1b" "\n\t" "3:"
106 static void __inline__ UnlockX86(volatile int *lock)
109 asm __volatile__("movl $0, (%1)":"=&q"(dummy)
113 # define LockInit(p) (p=0)
114 # define LockFree(p) (p=0)
115 # define Unlock(p) (UnlockX86(&p))
116 # define Lock(p) (LockX86(&p))
117 # define lock_t volatile int
121 # endif /* windows or unix */
128 #endif /* SMP code */