Fork us on GitHub Follow us on Facebook Follow us on Twitter

Ignore:
Timestamp:
2018-11-12T10:36:10Z (3 years ago)
Author:
GitHub <noreply@…>
Branches:
lfn, master
Children:
a43dfcb
Parents:
3ce781f4 (diff), 6874bd2 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
Jakub Jermář <jakub@…> (2018-11-12 10:36:10)
git-committer:
GitHub <noreply@…> (2018-11-12 10:36:10)
Message:

Merge pull request #56 from jermar/futexremoval

Remove kernel support for futexes in favor of waitq kobjects.

File:
1 edited

Legend:

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

    r3ce781f4 raaa3c457  
    4242#include <time.h>
    4343#include <fibril.h>
     44#include <abi/cap.h>
     45#include <abi/synch.h>
    4446
    4547typedef struct futex {
    4648        volatile atomic_int val;
     49        volatile cap_waitq_handle_t whandle;
     50
    4751#ifdef CONFIG_DEBUG_FUTEX
    4852        _Atomic(fibril_t *) owner;
     
    5054} futex_t;
    5155
    52 extern void futex_initialize(futex_t *futex, int value);
     56extern errno_t futex_initialize(futex_t *futex, int value);
     57
     58static 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}
    5368
    5469#ifdef CONFIG_DEBUG_FUTEX
    55 
    56 #define FUTEX_INITIALIZE(val) { (val) , NULL }
    57 #define FUTEX_INITIALIZER     FUTEX_INITIALIZE(1)
    5870
    5971void __futex_assert_is_locked(futex_t *, const char *);
     
    7486#else
    7587
    76 #define FUTEX_INITIALIZE(val) { (val) }
    77 #define FUTEX_INITIALIZER     FUTEX_INITIALIZE(1)
    78 
    7988#define futex_lock(fut)     (void) futex_down((fut))
    8089#define futex_trylock(fut)  futex_trydown((fut))
     
    8695
    8796#endif
     97
     98static inline errno_t futex_allocate_waitq(futex_t *futex)
     99{
     100        return __SYSCALL1(SYS_WAITQ_CREATE, (sysarg_t) &futex->whandle);
     101}
    88102
    89103/** Down the futex with timeout, composably.
     
    107121{
    108122        // TODO: Add tests for this.
     123
     124        assert(futex->whandle != CAP_NIL);
    109125
    110126        if (atomic_fetch_sub_explicit(&futex->val, 1, memory_order_acquire) > 0)
     
    132148        }
    133149
    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);
    135152}
    136153
     
    147164{
    148165        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);
    150167
    151168        return EOK;
Note: See TracChangeset for help on using the changeset viewer.