Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members

sync.h

00001 // Copyright (C) 2001 Jean-Marc Valin
00002 
00003 #ifndef SYNC_H
00004 #define SYNC_H
00005 
00006 #ifdef __i386__
00007 typedef int spinlock_t; 
00008 
00009 inline void spinlock_init(spinlock_t *spin)
00010 {
00011    (*spin)=1;
00012 }
00013 
00014 inline void spinlock_lock(spinlock_t *spin)
00015 {
00016    //Should use sched_yield on UP systems when we cannot lock
00017    __asm__ __volatile__ (
00018    "
00019    pushl %%ebx
00020 spin%=:
00021    xchg (%%eax), %%ebx
00022    cmp $0, %%ebx
00023    je spin%=
00024    popl %%ebx
00025    sfence
00026    "
00027    : : "a" (spin), "b" (int(0))
00028    : "memory"
00029    );
00030 }
00031 
00032 inline void spinlock_unlock(spinlock_t *spin)
00033 {
00034    *spin=1;
00035 }
00036 #else
00037 
00038 #include <pthread.h>
00039 
00040 typedef pthread_mutex_t spinlock_t;
00041 
00042 #define spinlock_init pthread_mutex_init
00043 
00044 #define spinlock_lock pthread_mutex_lock
00045 
00046 #define spinlock_unlock pthread_mutex_unlock
00047 
00048 #endif /*ifdef __i386__*/
00049 
00050 
00051 #endif /*ifndef SYNC_H*/

Generated on Wed Oct 5 14:28:56 2005 for FlowDesigner by  doxygen 1.4.4