Changeset cb10bc9 in mainline


Ignore:
Timestamp:
2012-12-04T02:21:03Z (11 years ago)
Author:
Adam Hraska <adam.hraska+hos@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1b7eec9
Parents:
927a181e
Message:

Inlined uspace futex functions.

Location:
uspace/lib/c
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/futex.c

    r927a181e rcb10bc9  
    3535#include <futex.h>
    3636#include <atomic.h>
    37 #include <libc.h>
    38 #include <sys/types.h>
    3937
    4038/** Initialize futex counter.
     
    4947}
    5048
    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 }
    9649
    9750/** @}
  • uspace/lib/c/include/futex.h

    r927a181e rcb10bc9  
    3838#include <atomic.h>
    3939#include <sys/types.h>
     40#include <libc.h>
     41
    4042
    4143#define FUTEX_INITIALIZER  {{1}}
     
    4547} futex_t;
    4648
     49
    4750extern 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 */
     65static 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 */
     79static 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 */
     95static 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}
    51102
    52103#endif
Note: See TracChangeset for help on using the changeset viewer.