1 /* *INDENT-OFF* */ 2 #if (CPUS > 1) 3 # if !defined(UNIX) 4 /* 5 ******************************************************************************* 6 * * 7 * this is a Microsoft windows-based operating system. * 8 * * 9 ******************************************************************************* 10 */ 11 # include <windows.h> 12 # define pthread_attr_t HANDLE 13 # define pthread_t HANDLE 14 # define thread_t HANDLE 15 extern pthread_t NumaStartThread(void *func, void *args); 16 17 # include <windows.h> 18 typedef volatile LONG lock_t[1]; 19 20 # define LockInit(v) ((v)[0] = 0) 21 # define LockFree(v) ((v)[0] = 0) 22 # define Unlock(v) ((v)[0] = 0) Lock(volatile LONG * hPtr)23__forceinline void Lock(volatile LONG * hPtr) { 24 int iValue; 25 26 for (;;) { 27 iValue = _InterlockedExchange((LPLONG) hPtr, 1); 28 if (0 == iValue) 29 return; 30 while (*hPtr); 31 } 32 } Pause()33void Pause() { 34 } 35 # else 36 /* 37 ******************************************************************************* 38 * * 39 * this is a Unix-based operating system. define the spinlock code as needed * 40 * for SMP synchronization. * 41 * * 42 ******************************************************************************* 43 */ LockX86(volatile int * lock)44static void __inline__ LockX86(volatile int *lock) { 45 int dummy; 46 asm __volatile__( 47 "1: movl $1, %0" "\n\t" 48 " xchgl (%1), %0" "\n\t" 49 " testl %0, %0" "\n\t" 50 " jz 3f" "\n\t" 51 "2: pause" "\n\t" 52 " movl (%1), %0" "\n\t" 53 " testl %0, %0" "\n\t" 54 " jnz 2b" "\n\t" 55 " jmp 1b" "\n\t" 56 "3:" "\n\t" 57 :"=&q"(dummy) 58 :"q"(lock) 59 :"cc", "memory"); 60 } Pause()61static void __inline__ Pause() { 62 asm __volatile__( 63 " pause" "\n\t"); 64 } UnlockX86(volatile int * lock)65static void __inline__ UnlockX86(volatile int *lock) { 66 asm __volatile__( 67 "movl $0, (%0)" 68 : 69 :"q"(lock) 70 :"memory"); 71 } 72 73 # define LockInit(p) (p=0) 74 # define LockFree(p) (p=0) 75 # define Unlock(p) (UnlockX86(&p)) 76 # define Lock(p) (LockX86(&p)) 77 # define lock_t volatile int 78 # endif 79 #else 80 # define LockInit(p) 81 # define LockFree(p) 82 # define Lock(p) 83 # define Unlock(p) 84 # define lock_t volatile int 85 #endif /* SMP code */ 86 /* *INDENT-ON* */ 87