Changeset cb10bc9 in mainline
- 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
- Location:
- uspace/lib/c
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/futex.c
r927a181e rcb10bc9 35 35 #include <futex.h> 36 36 #include <atomic.h> 37 #include <libc.h>38 #include <sys/types.h>39 37 40 38 /** Initialize futex counter. … … 49 47 } 50 48 51 /** Try to down the futex.52 *53 * @param futex Futex.54 *55 * @return Non-zero if the futex was acquired.56 * @return Zero if the futex was not acquired.57 *58 */59 int futex_trydown(futex_t *futex)60 {61 return cas(&futex->val, 1, 0);62 }63 64 /** Down the futex.65 *66 * @param futex Futex.67 *68 * @return ENOENT if there is no such virtual address.69 * @return Zero in the uncontended case.70 * @return Otherwise one of ESYNCH_OK_ATOMIC or ESYNCH_OK_BLOCKED.71 *72 */73 int futex_down(futex_t *futex)74 {75 if ((atomic_signed_t) atomic_predec(&futex->val) < 0)76 return __SYSCALL1(SYS_FUTEX_SLEEP, (sysarg_t) &futex->val.count);77 78 return 0;79 }80 81 /** Up the futex.82 *83 * @param futex Futex.84 *85 * @return ENOENT if there is no such virtual address.86 * @return Zero in the uncontended case.87 *88 */89 int futex_up(futex_t *futex)90 {91 if ((atomic_signed_t) atomic_postinc(&futex->val) < 0)92 return __SYSCALL1(SYS_FUTEX_WAKEUP, (sysarg_t) &futex->val.count);93 94 return 0;95 }96 49 97 50 /** @} -
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.