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