Changeset 9e889f6 in mainline
- Timestamp:
- 2018-11-11T15:46:26Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0b5203b
- Parents:
- d314571
- git-author:
- Jakub Jermar <jakub@…> (2018-11-10 14:53:45)
- git-committer:
- Jakub Jermar <jakub@…> (2018-11-11 15:46:26)
- Location:
- uspace/lib/c/generic
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/private/futex.h
rd314571 r9e889f6 42 42 #include <time.h> 43 43 #include <fibril.h> 44 #include <abi/cap.h> 44 45 45 46 typedef struct futex { 46 47 volatile atomic_int val; 48 volatile atomic_int alloc_lock; 49 cap_waitq_handle_t whandle; 50 47 51 #ifdef CONFIG_DEBUG_FUTEX 48 52 _Atomic(fibril_t *) owner; … … 54 58 #ifdef CONFIG_DEBUG_FUTEX 55 59 56 #define FUTEX_INITIALIZE(val) { (val) 60 #define FUTEX_INITIALIZE(val) { (val), 0, CAP_NIL, NULL } 57 61 #define FUTEX_INITIALIZER FUTEX_INITIALIZE(1) 58 62 … … 74 78 #else 75 79 76 #define FUTEX_INITIALIZE(val) { (val) }80 #define FUTEX_INITIALIZE(val) { (val), 0, CAP_NIL } 77 81 #define FUTEX_INITIALIZER FUTEX_INITIALIZE(1) 78 82 … … 132 136 } 133 137 134 return __SYSCALL2(SYS_FUTEX_SLEEP, (sysarg_t) futex, (sysarg_t) timeout); 138 if (futex->whandle == CAP_NIL) { 139 while (atomic_exchange_explicit(&futex->alloc_lock, 1, 140 memory_order_acquire) == 1) 141 ; 142 if (futex->whandle == CAP_NIL) { 143 errno_t rc = __SYSCALL1(SYS_WAITQ_CREATE, 144 (sysarg_t) &futex->whandle); 145 if (rc != EOK) { 146 atomic_store_explicit(&futex->alloc_lock, 0, 147 memory_order_release); 148 return rc; 149 } 150 } 151 152 atomic_store_explicit(&futex->alloc_lock, 0, 153 memory_order_release); 154 } 155 156 return __SYSCALL2(SYS_WAITQ_SLEEP, (sysarg_t) futex->whandle, 157 (sysarg_t) timeout); 135 158 } 136 159 … … 147 170 { 148 171 if (atomic_fetch_add_explicit(&futex->val, 1, memory_order_release) < 0) 149 return __SYSCALL1(SYS_ FUTEX_WAKEUP, (sysarg_t) futex);172 return __SYSCALL1(SYS_WAITQ_WAKEUP, (sysarg_t) futex->whandle); 150 173 151 174 return EOK; -
uspace/lib/c/generic/thread/futex.c
rd314571 r9e889f6 53 53 { 54 54 atomic_store_explicit(&futex->val, val, memory_order_relaxed); 55 atomic_store_explicit(&futex->alloc_lock, 0, memory_order_relaxed); 56 futex->whandle = CAP_NIL; 55 57 } 56 58
Note:
See TracChangeset
for help on using the changeset viewer.