Changeset cb10bc9 in mainline for uspace/lib/c/include/futex.h
- Timestamp:
- 2012-12-04T02:21:03Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1b7eec9
- Parents:
- 927a181e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/include/futex.h
r927a181e rcb10bc9 38 38 #include <atomic.h> 39 39 #include <sys/types.h> 40 #include <libc.h> 41 40 42 41 43 #define FUTEX_INITIALIZER {{1}} … … 45 47 } futex_t; 46 48 49 47 50 extern void futex_initialize(futex_t *futex, int value); 48 extern int futex_down(futex_t *futex); 49 extern int futex_trydown(futex_t *futex); 50 extern int futex_up(futex_t *futex); 51 52 #define futex_down(fut) (void)_futex_down((fut)) 53 #define futex_trydown(fut) _futex_trydown((fut)) 54 #define futex_up(fut) (void)_futex_up((fut)) 55 56 57 /** Try to down the futex. 58 * 59 * @param futex Futex. 60 * 61 * @return Non-zero if the futex was acquired. 62 * @return Zero if the futex was not acquired. 63 * 64 */ 65 static inline int _futex_trydown(futex_t *futex) 66 { 67 return cas(&futex->val, 1, 0); 68 } 69 70 /** Down the futex. 71 * 72 * @param futex Futex. 73 * 74 * @return ENOENT if there is no such virtual address. 75 * @return Zero in the uncontended case. 76 * @return Otherwise one of ESYNCH_OK_ATOMIC or ESYNCH_OK_BLOCKED. 77 * 78 */ 79 static inline int _futex_down(futex_t *futex) 80 { 81 if ((atomic_signed_t) atomic_predec(&futex->val) < 0) 82 return __SYSCALL1(SYS_FUTEX_SLEEP, (sysarg_t) &futex->val.count); 83 84 return 0; 85 } 86 87 /** Up the futex. 88 * 89 * @param futex Futex. 90 * 91 * @return ENOENT if there is no such virtual address. 92 * @return Zero in the uncontended case. 93 * 94 */ 95 static inline int _futex_up(futex_t *futex) 96 { 97 if ((atomic_signed_t) atomic_postinc(&futex->val) < 0) 98 return __SYSCALL1(SYS_FUTEX_WAKEUP, (sysarg_t) &futex->val.count); 99 100 return 0; 101 } 51 102 52 103 #endif
Note:
See TracChangeset
for help on using the changeset viewer.