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