Changeset 27336 in webkit for trunk/JavaScriptCore/wtf/TCSpinLock.h
- Timestamp:
- Oct 31, 2007, 6:22:35 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wtf/TCSpinLock.h
r27295 r27336 34 34 #define TCMALLOC_INTERNAL_SPINLOCK_H__ 35 35 36 #if (PLATFORM(X86) || PLATFORM(PPC)) && COMPILER(GCC)36 #if (PLATFORM(X86) || PLATFORM(PPC)) && (COMPILER(GCC) || COMPILER(MSVC)) 37 37 38 38 #include <time.h> /* For nanosleep() */ … … 48 48 #endif 49 49 #include <stdlib.h> /* for abort() */ 50 51 #if COMPILER(MSVC) 52 #define WIN32_LEAN_AND_MEAN 53 #include <windows.h> 54 #endif 50 55 51 56 static void TCMalloc_SlowLock(volatile unsigned int* lockword); … … 60 65 inline void Lock() { 61 66 int r; 67 #if COMPILER(GCC) 62 68 #if PLATFORM(X86) 63 69 __asm__ __volatile__ … … 77 83 : "memory"); 78 84 #endif 85 #elif COMPILER(MSVC) 86 __asm { 87 mov eax, this ; store &private_lockword_ (which is this+0) in eax 88 mov ebx, 1 ; store 1 in ebx 89 xchg [eax], ebx ; exchange private_lockword_ and 1 90 mov r, ebx ; store old value of private_lockword_ in r 91 } 92 #endif 79 93 if (r) TCMalloc_SlowLock(&private_lockword_); 80 94 } 81 95 82 96 inline void Unlock() { 97 #if COMPILER(GCC) 83 98 #if PLATFORM(X86) 84 99 __asm__ __volatile__ … … 96 111 : "memory"); 97 112 #endif 113 #elif COMPILER(MSVC) 114 __asm { 115 mov eax, this ; store &private_lockword_ (which is this+0) in eax 116 mov [eax], 0 ; set private_lockword_ to 0 117 } 118 #endif 98 119 } 99 120 … … 111 132 while (true) { 112 133 int r; 134 #if COMPILER(GCC) 113 135 #if PLATFORM(X86) 114 136 __asm__ __volatile__ … … 128 150 : "r" (tmp), "1" (lockword) 129 151 : "memory"); 152 #endif 153 #elif COMPILER(MSVC) 154 __asm { 155 mov eax, lockword ; assign lockword into eax 156 mov ebx, 1 ; assign 1 into ebx 157 xchg [eax], ebx ; exchange *lockword and 1 158 mov r, ebx ; store old value of *lockword in r 159 } 130 160 #endif 131 161 if (!r) { … … 143 173 144 174 // Sleep for a few milliseconds 175 #if COMPILER(MSVC) 176 Sleep(2); 177 #else 145 178 struct timespec tm; 146 179 tm.tv_sec = 0; 147 180 tm.tv_nsec = 2000001; 148 181 nanosleep(&tm, NULL); 182 #endif 149 183 } 150 184 } 151 152 #elif COMPILER(MSVC)153 154 #define WIN32_LEAN_AND_MEAN155 #include <windows.h>156 157 struct TCMalloc_SpinLock {158 CRITICAL_SECTION private_lock_;159 160 inline TCMalloc_SpinLock() {161 Init();162 }163 164 inline void Init() {165 InitializeCriticalSection(&private_lock_);166 }167 inline void Finalize() {168 DeleteCriticalSection(&private_lock_);169 }170 inline void Lock() {171 EnterCriticalSection(&private_lock_);172 }173 inline void Unlock() {174 LeaveCriticalSection(&private_lock_);175 }176 };177 185 178 186 #else
Note:
See TracChangeset
for help on using the changeset viewer.