PFUNC 1.0
pfunc/futex.h
Go to the documentation of this file.
00001 #ifndef PFUNC_FUTEX_H
00002 #define PFUNC_FUTEX_H
00003 
00004 #if PFUNC_HAVE_SYSCALL_H == 1
00005 #include <sys/syscall.h>
00006 #endif
00007 
00008 #if PFUNC_HAVE_UNISTD_H == 1
00009 #include <unistd.h>
00010 #endif
00011 
00012 #if PFUNC_HAVE_ERRNO_H == 1
00013 #include <errno.h>
00014 #endif
00015 
00016 #ifndef SYS_futex
00017 #warning "SYS_futex not defined"
00018 #define SYS_futex 202
00019 #endif
00020 
00021 #include <pfunc/environ.hpp>
00022 
00023 #define FUTEX_WAIT 0
00024 #define FUTEX_WAKE 1
00025 
00026 #ifdef __cplusplus
00027 extern "C" {
00028 #endif
00029 
00040 static PFUNC_INLINE void futex_wait (int* addr, int val) {
00041   syscall (SYS_futex, addr, FUTEX_WAIT, val, NULL, NULL, 0);
00042 }
00043 
00051 static PFUNC_INLINE void futex_wake (int *addr, int nthreads) {
00052   syscall (SYS_futex, addr, FUTEX_WAKE, nthreads, NULL, NULL, 0);
00053 }
00054 
00058 static PFUNC_INLINE void cpu_relax (void) {
00059 #if PFUNC_X86 == 1
00060   __asm__ __volatile__ ("rep; nop" : : : "memory");
00061 #else
00062 
00063 #endif
00064 }
00065 
00066 #ifdef __cplusplus
00067 }
00068 #endif
00069 
00070 #endif /* PFUNC_FUTEX_H */