Changes in uspace/lib/c/generic/private/futex.h [0b8fad2:42da5ed] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/private/futex.h
r0b8fad2 r42da5ed 42 42 #include <time.h> 43 43 #include <fibril.h> 44 #include <abi/cap.h>45 #include <abi/synch.h>46 44 47 45 typedef struct futex { 48 46 volatile atomic_int val; 49 volatile cap_waitq_handle_t whandle;50 51 47 #ifdef CONFIG_DEBUG_FUTEX 52 48 _Atomic(fibril_t *) owner; … … 54 50 } futex_t; 55 51 56 extern errno_t futex_initialize(futex_t *futex, int value); 57 58 static inline errno_t futex_destroy(futex_t *futex) 59 { 60 if (futex->whandle) { 61 errno_t rc; 62 rc = __SYSCALL1(SYS_WAITQ_DESTROY, (sysarg_t) futex->whandle); 63 futex->whandle = CAP_NIL; 64 return rc; 65 } 66 return EOK; 67 } 52 extern void futex_initialize(futex_t *futex, int value); 68 53 69 54 #ifdef CONFIG_DEBUG_FUTEX 55 56 #define FUTEX_INITIALIZE(val) { (val) , NULL } 57 #define FUTEX_INITIALIZER FUTEX_INITIALIZE(1) 70 58 71 59 void __futex_assert_is_locked(futex_t *, const char *); … … 86 74 #else 87 75 76 #define FUTEX_INITIALIZE(val) { (val) } 77 #define FUTEX_INITIALIZER FUTEX_INITIALIZE(1) 78 88 79 #define futex_lock(fut) (void) futex_down((fut)) 89 80 #define futex_trylock(fut) futex_trydown((fut)) … … 95 86 96 87 #endif 97 98 static inline errno_t futex_allocate_waitq(futex_t *futex)99 {100 return __SYSCALL1(SYS_WAITQ_CREATE, (sysarg_t) &futex->whandle);101 }102 88 103 89 /** Down the futex with timeout, composably. … … 121 107 { 122 108 // TODO: Add tests for this. 123 124 assert(futex->whandle != CAP_NIL);125 109 126 110 if (atomic_fetch_sub_explicit(&futex->val, 1, memory_order_acquire) > 0) … … 148 132 } 149 133 150 return __SYSCALL3(SYS_WAITQ_SLEEP, (sysarg_t) futex->whandle, 151 (sysarg_t) timeout, (sysarg_t) SYNCH_FLAGS_FUTEX); 134 return __SYSCALL2(SYS_FUTEX_SLEEP, (sysarg_t) futex, (sysarg_t) timeout); 152 135 } 153 136 … … 164 147 { 165 148 if (atomic_fetch_add_explicit(&futex->val, 1, memory_order_release) < 0) 166 return __SYSCALL1(SYS_ WAITQ_WAKEUP, (sysarg_t) futex->whandle);149 return __SYSCALL1(SYS_FUTEX_WAKEUP, (sysarg_t) futex); 167 150 168 151 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.