Changeset 300
- Timestamp:
- 02/15/07 17:39:22 (1 year ago)
- Files:
-
- eaccelerator/trunk/ChangeLog (modified) (1 diff)
- eaccelerator/trunk/mm.c (modified) (2 diffs)
- eaccelerator/trunk/x86_spinlocks.h (deleted)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
eaccelerator/trunk/ChangeLog
r299 r300 7 7 or we run into a machine with windows and VC windows support wil be 8 8 b0rked. 9 * Move spinlock stuff into mm.c, no need for an extra file with extra 10 indirection. 9 11 10 12 2007-02-13 Bart Vanbrabant <bart.vanbrabant at zoeloelip.be> eaccelerator/trunk/mm.c
r288 r300 175 175 #if defined(MM_SEM_SPINLOCK) 176 176 177 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) 178 # include "x86_spinlocks.h" 179 #else 177 #if !defined(__GNUC__) || !(defined(__i386__) || defined(__x86_64__)) 180 178 # error "spinlocks are not implemented for your system" 181 179 #endif … … 190 188 #define MM_SEM_CAN_ATTACH 191 189 190 #define EA_DEBUG_SPINLOCK 191 #define EA_SPINLOCK_TIMEOUT 2 192 192 193 typedef struct mm_mutex { 193 spinlock_t spinlock; 194 volatile unsigned int lock; 195 volatile pid_t pid; 196 volatile int locked; 197 #ifdef EA_DEBUG_SPINLOCK 198 time_t timestamp; 199 #endif 194 200 } mm_mutex; 195 201 196 static int mm_init_lock(const char* key, mm_mutex* lock) { 197 spinlock_init(&lock->spinlock); 198 return 1; 199 } 200 201 static int mm_do_lock(mm_mutex* lock, int kind) { 202 spinlock_lock(&lock->spinlock); 203 return 1; 202 #define spinlock_try_lock(rw) asm volatile("lock ; decl %0" :"=m" ((rw)->lock) : : "memory") 203 #define _spinlock_unlock(rw) asm volatile("lock ; incl %0" :"=m" ((rw)->lock) : : "memory") 204 205 static int mm_init_lock(const char* key, mm_mutex* lock) 206 { 207 lock->lock = 0x1; 208 lock->pid = -1; 209 lock->locked = 0; 210 #ifdef EA_DEBUG_SPINLOCK 211 lock->timestamp = 0; 212 #endif 213 return 1; 214 } 215 216 static int mm_do_lock(mm_mutex* lock, int kind) 217 { 218 #ifdef EA_DEBUG_SPINLOCK 219 lock->timestamp = time(0); 220 #endif 221 while (1) { 222 spinlock_try_lock(lock); 223 if (lock->lock == 0) { 224 lock->pid = getpid(); 225 lock->locked = 1; 226 return 1; 227 } 228 #ifdef EA_DEBUG_SPINLOCK 229 else { 230 if (lock->timestamp >= time(0) + EA_SPINLOCK_TIMEOUT) { 231 ea_debug_error("Lock time-out, exiting\n"); 232 return 0; 233 } 234 } 235 #endif 236 _spinlock_unlock(lock); 237 } 238 return 1; 204 239 } 205 240 206 241 static int mm_do_unlock(mm_mutex* lock) { 207 spinlock_unlock(&lock->spinlock); 208 return 1; 242 if (lock->locked && (lock->pid == getpid())) { 243 lock->pid = 0; 244 lock->locked = 0; 245 _spinlock_unlock(lock); 246 } 247 return 1; 209 248 } 210 249