Changeset 235d31d in mainline for uspace/lib/c/generic/futex.c


Ignore:
Timestamp:
2014-12-22T17:47:40Z (9 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8c7d5ad
Parents:
eae91e0 (diff), 759ea0d (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.
Message:

Merge the CHT pre-integration branch

This branch contains:

  • the merge of lp:~adam-hraska+lp/helenos/rcu, which brings:
  • a new preemptible kernel RCU variant called A-RCU,
  • a preemptible variant of Podzimek's non-preemptible kernel RCU and
  • a new variant of usersace RCU,
  • a new concurrent hash table (CHT) implementation based on RCU,
  • a deployment of CHT in kernel futex handling,
  • a deployment of the userspace RCU in the implementation of upgradable futexes,

all described in Adam Hraska's master thesis named Read-Copy-Update
for HelenOS, defended in 2013 at MFF UK; furthemore, the branch
fixes two synchronization bugs in condvars and waitq, respectively:

  • revid:adam.hraska+hos@gmail.com-20121116144921-3to9u1tn1sg07rg7
  • revid:adam.hraska+hos@gmail.com-20121116173623-km7gwtqixwudpe66
  • build fixes required to pass make check
  • overhaul of ia64 and sparc64 trap handling, to allow exc_dispatch() to be used now when the kernel is more picky about CPU state accounting
  • an important fix of the sparc64/sun4v preemptible trap handler
  • various other fixes of issues discovered on non-x86 architectures
File:
1 edited

Legend:

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

    reae91e0 r235d31d  
    3535#include <futex.h>
    3636#include <atomic.h>
    37 #include <libarch/barrier.h>
    38 #include <libc.h>
    39 #include <sys/types.h>
    4037
    4138/** Initialize futex counter.
     
    4744void futex_initialize(futex_t *futex, int val)
    4845{
    49         atomic_set(futex, val);
     46        atomic_set(&futex->val, val);
    5047}
    5148
    52 /** Try to down the futex.
    53  *
    54  * @param futex Futex.
    55  *
    56  * @return Non-zero if the futex was acquired.
    57  * @return Zero if the futex was not acquired.
    58  *
    59  */
    60 int futex_trydown(futex_t *futex)
     49
     50#ifdef FUTEX_UPGRADABLE
     51
     52int _upgrade_futexes = 0;
     53static futex_t upg_and_wait_futex = FUTEX_INITIALIZER;
     54
     55void futex_upgrade_all_and_wait(void)
    6156{
    62         int rc;
    63 
    64         rc = cas(futex, 1, 0);
    65         CS_ENTER_BARRIER();
    66 
    67         return rc;
     57        futex_down(&upg_and_wait_futex);
     58       
     59        if (!_upgrade_futexes) {
     60                rcu_assign(_upgrade_futexes, 1);
     61                _rcu_synchronize(BM_BLOCK_THREAD);
     62        }
     63       
     64        futex_up(&upg_and_wait_futex);
    6865}
    6966
    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 int futex_down(futex_t *futex)
    80 {
    81         atomic_signed_t nv;
    82 
    83         nv = (atomic_signed_t) atomic_predec(futex);
    84         CS_ENTER_BARRIER();
    85         if (nv < 0)
    86                 return __SYSCALL1(SYS_FUTEX_SLEEP, (sysarg_t) &futex->count);
    87        
    88         return 0;
    89 }
    90 
    91 /** Up the futex.
    92  *
    93  * @param futex Futex.
    94  *
    95  * @return ENOENT if there is no such virtual address.
    96  * @return Zero in the uncontended case.
    97  *
    98  */
    99 int futex_up(futex_t *futex)
    100 {
    101         CS_LEAVE_BARRIER();
    102 
    103         if ((atomic_signed_t) atomic_postinc(futex) < 0)
    104                 return __SYSCALL1(SYS_FUTEX_WAKEUP, (sysarg_t) &futex->count);
    105        
    106         return 0;
    107 }
     67#endif
    10868
    10969/** @}
Note: See TracChangeset for help on using the changeset viewer.