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

Changeset 9e889f6 in mainline


Ignore:
Timestamp:
2018-11-11T15:46:26Z (3 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master
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)
Message:

Switch userspace futexes to using waitq kobjects

This replaces futexes entirely when they are not shared across address
spaces.

Location:
uspace/lib/c/generic
Files:
2 edited

Legend:

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

    rd314571 r9e889f6  
    4242#include <time.h>
    4343#include <fibril.h>
     44#include <abi/cap.h>
    4445
    4546typedef struct futex {
    4647        volatile atomic_int val;
     48        volatile atomic_int alloc_lock;
     49        cap_waitq_handle_t whandle;
     50
    4751#ifdef CONFIG_DEBUG_FUTEX
    4852        _Atomic(fibril_t *) owner;
     
    5458#ifdef CONFIG_DEBUG_FUTEX
    5559
    56 #define FUTEX_INITIALIZE(val) { (val) , NULL }
     60#define FUTEX_INITIALIZE(val) { (val), 0, CAP_NIL, NULL }
    5761#define FUTEX_INITIALIZER     FUTEX_INITIALIZE(1)
    5862
     
    7478#else
    7579
    76 #define FUTEX_INITIALIZE(val) { (val) }
     80#define FUTEX_INITIALIZE(val) { (val), 0, CAP_NIL }
    7781#define FUTEX_INITIALIZER     FUTEX_INITIALIZE(1)
    7882
     
    132136        }
    133137
    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);
    135158}
    136159
     
    147170{
    148171        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);
    150173
    151174        return EOK;
  • uspace/lib/c/generic/thread/futex.c

    rd314571 r9e889f6  
    5353{
    5454        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;
    5557}
    5658
Note: See TracChangeset for help on using the changeset viewer.