Rev 108 | Go to most recent revision | Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 33 | pmbaty | 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 | # include <intrin.h> // Pierre-Marie Baty -- for _InterlockedExchange() |
||
| 19 | # pragma intrinsic (_InterlockedExchange) |
||
| 20 | typedef volatile LONG lock_t[1]; |
||
| 21 | |||
| 22 | # define LockInit(v) ((v)[0] = 0) |
||
| 23 | # define LockFree(v) ((v)[0] = 0) |
||
| 24 | # define Unlock(v) ((v)[0] = 0) |
||
| 25 | __forceinline void Lock(volatile LONG * hPtr) { |
||
| 26 | int iValue; |
||
| 27 | |||
| 28 | for (;;) { |
||
| 29 | iValue = _InterlockedExchange((LPLONG) hPtr, 1); |
||
| 30 | if (0 == iValue) |
||
| 31 | return; |
||
| 32 | while (*hPtr); |
||
| 33 | } |
||
| 34 | } |
||
| 35 | void Pause() { |
||
| 36 | } |
||
| 37 | # else |
||
| 38 | /* |
||
| 39 | ******************************************************************************* |
||
| 40 | * * |
||
| 41 | * this is a Unix-based operating system. define the spinlock code as needed * |
||
| 42 | * for SMP synchronization. * |
||
| 43 | * * |
||
| 44 | ******************************************************************************* |
||
| 45 | */ |
||
| 46 | static void __inline__ LockX86(volatile int *lock) { |
||
| 47 | int dummy; |
||
| 48 | asm __volatile__( |
||
| 49 | "1: movl $1, %0" "\n\t" |
||
| 50 | " xchgl (%1), %0" "\n\t" |
||
| 51 | " testl %0, %0" "\n\t" |
||
| 52 | " jz 3f" "\n\t" |
||
| 53 | "2: pause" "\n\t" |
||
| 54 | " movl (%1), %0" "\n\t" |
||
| 55 | " testl %0, %0" "\n\t" |
||
| 56 | " jnz 2b" "\n\t" |
||
| 57 | " jmp 1b" "\n\t" |
||
| 58 | "3:" "\n\t" |
||
| 59 | :"=&q"(dummy) |
||
| 60 | :"q"(lock) |
||
| 61 | :"cc", "memory"); |
||
| 62 | } |
||
| 63 | static void __inline__ Pause() { |
||
| 64 | asm __volatile__( |
||
| 65 | " pause" "\n\t"); |
||
| 66 | } |
||
| 67 | static void __inline__ UnlockX86(volatile int *lock) { |
||
| 68 | asm __volatile__( |
||
| 69 | "movl $0, (%0)" |
||
| 70 | : |
||
| 71 | :"q"(lock) |
||
| 72 | :"memory"); |
||
| 73 | } |
||
| 74 | |||
| 75 | # define LockInit(p) (p=0) |
||
| 76 | # define LockFree(p) (p=0) |
||
| 77 | # define Unlock(p) (UnlockX86(&p)) |
||
| 78 | # define Lock(p) (LockX86(&p)) |
||
| 79 | # define lock_t volatile int |
||
| 80 | # endif |
||
| 81 | #else |
||
| 82 | # define LockInit(p) |
||
| 83 | # define LockFree(p) |
||
| 84 | # define Lock(p) |
||
| 85 | # define Unlock(p) |
||
| 86 | # define lock_t volatile int |
||
| 87 | #endif /* SMP code */ |
||
| 88 | /* *INDENT-ON* */ |