Changeset b1c57a8 in mainline for uspace/lib/c/generic/futex.c


Ignore:
Timestamp:
2014-10-09T15:03:55Z (10 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e367939c
Parents:
21799398 (diff), 207e8880 (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 from lp:~adam-hraska+lp/helenos/rcu/.

Only merge from the feature branch and resolve all conflicts.

File:
1 edited

Legend:

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

    r21799398 rb1c57a8  
    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.