Subversion Repositories Games.Chess Giants

Rev

Rev 33 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 33 Rev 108
Line 13... Line 13...
13
#    define pthread_t       HANDLE
13
#    define pthread_t       HANDLE
14
#    define thread_t        HANDLE
14
#    define thread_t        HANDLE
15
extern pthread_t NumaStartThread(void *func, void *args);
15
extern pthread_t NumaStartThread(void *func, void *args);
16
 
16
 
17
#    include <windows.h>
17
#    include <windows.h>
18
#    include <intrin.h> // Pierre-Marie Baty -- for _InterlockedExchange()
18
//#    pragma intrinsic (_InterlockedExchange) // Pierre-Marie Baty -- it's already intrinsic, and there's no leading underscore
19
#    pragma intrinsic (_InterlockedExchange)
-
 
20
typedef volatile LONG lock_t[1];
19
typedef volatile LONG lock_t[1];
21
 
20
 
22
#    define LockInit(v)      ((v)[0] = 0)
21
#    define LockInit(v)      ((v)[0] = 0)
23
#    define LockFree(v)      ((v)[0] = 0)
22
#    define LockFree(v)      ((v)[0] = 0)
24
#    define Unlock(v)        ((v)[0] = 0)
23
#    define Unlock(v)        ((v)[0] = 0)
25
__forceinline void Lock(volatile LONG * hPtr) {
24
__forceinline void Lock(volatile LONG * hPtr) {
26
  int iValue;
25
  int iValue;
27
 
26
 
28
  for (;;) {
27
  for (;;) {
29
    iValue = _InterlockedExchange((LPLONG) hPtr, 1);
28
    iValue = /*_*/InterlockedExchange((LPLONG) hPtr, 1); // Pierre-Marie Baty -- no leading underscore
30
    if (0 == iValue)
29
    if (0 == iValue)
31
      return;
30
      return;
32
    while (*hPtr);
31
    while (*hPtr);
33
  }
32
  }
34
}
33
}
Line 44... Line 43...
44
 *******************************************************************************
43
 *******************************************************************************
45
 */
44
 */
46
static void __inline__ LockX86(volatile int *lock) {
45
static void __inline__ LockX86(volatile int *lock) {
47
  int dummy;
46
  int dummy;
48
  asm __volatile__(
47
  asm __volatile__(
49
      "1:          movl    $1, %0"   "\n\t"
48
      "1:          movl    $1, %0"          "\n\t"
50
      "            xchgl   (%1), %0" "\n\t"
49
      "            xchgl   (%1), %0"        "\n\t"
51
      "            testl   %0, %0"   "\n\t"
50
      "            testl   %0, %0"          "\n\t"
52
      "            jz      3f"       "\n\t"
51
      "            jz      3f"              "\n\t"
53
      "2:          pause"            "\n\t"
52
      "2:          pause"                   "\n\t"
54
      "            movl    (%1), %0" "\n\t"
53
      "            movl    (%1), %0"        "\n\t"
55
      "            testl   %0, %0"   "\n\t"
54
      "            testl   %0, %0"          "\n\t"
56
      "            jnz     2b"       "\n\t"
55
      "            jnz     2b"              "\n\t"
57
      "            jmp     1b"       "\n\t"
56
      "            jmp     1b"              "\n\t"
58
      "3:"                           "\n\t"
57
      "3:"                                  "\n\t"
59
      :"=&q"(dummy)
58
      :"=&q"(dummy)
60
      :"q"(lock)
59
      :"q"(lock)
61
      :"cc", "memory");
60
      :"cc", "memory");
62
}
61
}
63
static void __inline__ Pause() {
62
static void __inline__ Pause() {
64
  asm __volatile__(
63
  asm __volatile__(
65
      "            pause"            "\n\t");
64
      "            pause"                   "\n\t");
66
}
65
}
67
static void __inline__ UnlockX86(volatile int *lock) {
66
static void __inline__ UnlockX86(volatile int *lock) {
68
  asm __volatile__(
67
  asm __volatile__(
69
      "movl    $0, (%0)"
68
      "movl        $0, (%0)"
70
      :
69
      :
71
      :"q"(lock)
70
      :"q"(lock)
72
      :"memory");
71
      :"memory");
73
}
72
}
74
 
73
 
Line 81... Line 80...
81
#else
80
#else
82
#  define LockInit(p)
81
#  define LockInit(p)
83
#  define LockFree(p)
82
#  define LockFree(p)
84
#  define Lock(p)
83
#  define Lock(p)
85
#  define Unlock(p)
84
#  define Unlock(p)
86
#  define lock_t volatile int
85
#  define lock_t                volatile int
87
#endif                          /*  SMP code */
86
#endif /*  SMP code */
88
/* *INDENT-ON* */
87
/* *INDENT-ON* */