00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <sys/syscall.h>
00028 #define FUTEX_WAIT 0
00029 #define FUTEX_WAKE 1
00030
00031 static inline void
00032 sys_futex0 (int *addr, int op, int val)
00033 {
00034 register unsigned long __v0 asm("$2") = (unsigned long) SYS_futex;
00035 register unsigned long __a0 asm("$4") = (unsigned long) addr;
00036 register unsigned long __a1 asm("$5") = (unsigned long) op;
00037 register unsigned long __a2 asm("$6") = (unsigned long) val;
00038 register unsigned long __a3 asm("$7") = 0;
00039
00040 __asm volatile ("syscall"
00041
00042 : "=r" (__v0), "=r" (__a3)
00043
00044 : "r" (__v0), "r" (__a0), "r" (__a1), "r" (__a2), "r" (__a3)
00045
00046 : "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13", "$14",
00047 "$15", "$24", "$25", "memory");
00048 }
00049
00050 static inline void
00051 futex_wait (int *addr, int val)
00052 {
00053 sys_futex0 (addr, FUTEX_WAIT, val);
00054 }
00055
00056 static inline void
00057 futex_wake (int *addr, int count)
00058 {
00059 sys_futex0 (addr, FUTEX_WAKE, count);
00060 }
00061
00062 static inline void
00063 cpu_relax (void)
00064 {
00065 __asm volatile ("" : : : "memory");
00066 }
00067
00068 static inline void
00069 atomic_write_barrier (void)
00070 {
00071 __sync_synchronize ();
00072 }