Changeset 156b6406 in mainline


Ignore:
Timestamp:
2012-12-04T16:42:06Z (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:
b188002
Parents:
b7acf38
Message:

Differentiated futexes when used with mutex semantics from those with semaphore semantics.

Location:
uspace
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/rcubench/rcubench.c

    rb7acf38 r156b6406  
    137137       
    138138        /* Signal another thread completed. */
    139         _futex_up(&bench->done_threads);
     139        futex_up(&bench->done_threads);
    140140}
    141141
     
    171171        /* Wait for threads to complete. */
    172172        for (size_t k = 0; k < bench->nthreads; ++k) {
    173                 _futex_down(&bench->done_threads);
     173                futex_down(&bench->done_threads);
    174174        }
    175175}
  • uspace/lib/c/generic/futex.c

    rb7acf38 r156b6406  
    5656void futex_upgrade_all_and_wait(void)
    5757{
    58         _futex_down(&upg_and_wait_futex);
     58        futex_down(&upg_and_wait_futex);
    5959       
    6060        if (!_upgrade_futexes) {
     
    6363        }
    6464       
    65         _futex_up(&upg_and_wait_futex);
     65        futex_up(&upg_and_wait_futex);
    6666}
    6767
  • uspace/lib/c/generic/malloc.c

    rb7acf38 r156b6406  
    200200        do { \
    201201                if (!(expr)) {\
    202                         _futex_up(&malloc_futex); \
     202                        futex_up(&malloc_futex); \
    203203                        assert_abort(#expr, __FILE__, __LINE__); \
    204204                } \
     
    785785void *malloc(const size_t size)
    786786{
    787         _futex_down(&malloc_futex);
     787        futex_down(&malloc_futex);
    788788        void *block = malloc_internal(size, BASE_ALIGN);
    789         _futex_up(&malloc_futex);
     789        futex_up(&malloc_futex);
    790790
    791791        return block;
     
    808808            1 << (fnzb(max(sizeof(void *), align) - 1) + 1);
    809809
    810         _futex_down(&malloc_futex);
     810        futex_down(&malloc_futex);
    811811        void *block = malloc_internal(size, palign);
    812         _futex_up(&malloc_futex);
     812        futex_up(&malloc_futex);
    813813
    814814        return block;
     
    828828                return malloc(size);
    829829       
    830         _futex_down(&malloc_futex);
     830        futex_down(&malloc_futex);
    831831       
    832832        /* Calculate the position of the header. */
     
    885885        }
    886886       
    887         _futex_up(&malloc_futex);
     887        futex_up(&malloc_futex);
    888888       
    889889        if (reloc) {
     
    908908                return;
    909909       
    910         _futex_down(&malloc_futex);
     910        futex_down(&malloc_futex);
    911911       
    912912        /* Calculate the position of the header. */
     
    953953        heap_shrink(area);
    954954       
    955         _futex_up(&malloc_futex);
     955        futex_up(&malloc_futex);
    956956}
    957957
    958958void *heap_check(void)
    959959{
    960         _futex_down(&malloc_futex);
     960        futex_down(&malloc_futex);
    961961       
    962962        if (first_heap_area == NULL) {
    963                 _futex_up(&malloc_futex);
     963                futex_up(&malloc_futex);
    964964                return (void *) -1;
    965965        }
     
    975975                    (((uintptr_t) area->start % PAGE_SIZE) != 0) ||
    976976                    (((uintptr_t) area->end % PAGE_SIZE) != 0)) {
    977                         _futex_up(&malloc_futex);
     977                        futex_up(&malloc_futex);
    978978                        return (void *) area;
    979979                }
     
    986986                        /* Check heap block consistency */
    987987                        if (head->magic != HEAP_BLOCK_HEAD_MAGIC) {
    988                                 _futex_up(&malloc_futex);
     988                                futex_up(&malloc_futex);
    989989                                return (void *) head;
    990990                        }
     
    994994                        if ((foot->magic != HEAP_BLOCK_FOOT_MAGIC) ||
    995995                            (head->size != foot->size)) {
    996                                 _futex_up(&malloc_futex);
     996                                futex_up(&malloc_futex);
    997997                                return (void *) foot;
    998998                        }
     
    10001000        }
    10011001       
    1002         _futex_up(&malloc_futex);
     1002        futex_up(&malloc_futex);
    10031003       
    10041004        return NULL;
  • uspace/lib/c/include/futex.h

    rb7acf38 r156b6406  
    5555#define FUTEX_INITIALIZE(val) {{ (val) }, 0}
    5656
    57 #define futex_down(fut) \
     57#define futex_lock(fut) \
    5858({ \
    5959        rcu_read_lock(); \
    6060        (fut)->upgraded = rcu_access(_upgrade_futexes); \
    6161        if ((fut)->upgraded) \
    62                 (void) _futex_down((fut)); \
     62                (void) futex_down((fut)); \
    6363})
    6464
    65 #define futex_trydown(fut) \
     65#define futex_trylock(fut) \
    6666({ \
    6767        rcu_read_lock(); \
    6868        int _upgraded = rcu_access(_upgrade_futexes); \
    6969        if (_upgraded) { \
    70                 int _acquired = _futex_trydown((fut)); \
     70                int _acquired = futex_trydown((fut)); \
    7171                if (!_acquired) { \
    7272                        rcu_read_unlock(); \
     
    8181})
    8282               
    83 #define futex_up(fut) \
     83#define futex_unlock(fut) \
    8484({ \
    8585        if ((fut)->upgraded) \
    86                 (void) _futex_up((fut)); \
     86                (void) futex_up((fut)); \
    8787        rcu_read_unlock(); \
    8888})
     
    9696#define FUTEX_INITIALIZE(val) {{ (val) }}
    9797
    98 #define futex_down(fut)     (void)_futex_down((fut))
    99 #define futex_trydown(fut)  _futex_trydown((fut))
    100 #define futex_up(fut)       (void)_futex_up((fut))
     98#define futex_lock(fut)     (void) futex_down((fut))
     99#define futex_trylock(fut)  futex_trydown((fut))
     100#define futex_unlock(fut)   (void) futex_up((fut))
    101101               
    102102#endif
     
    112112 *
    113113 */
    114 static inline int _futex_trydown(futex_t *futex)
     114static inline int futex_trydown(futex_t *futex)
    115115{
    116116        return cas(&futex->val, 1, 0);
     
    126126 *
    127127 */
    128 static inline int _futex_down(futex_t *futex)
     128static inline int futex_down(futex_t *futex)
    129129{
    130130        if ((atomic_signed_t) atomic_predec(&futex->val) < 0)
     
    142142 *
    143143 */
    144 static inline int _futex_up(futex_t *futex)
     144static inline int futex_up(futex_t *futex)
    145145{
    146146        if ((atomic_signed_t) atomic_postinc(&futex->val) < 0)
  • uspace/lib/urcu/rcu.c

    rb7acf38 r156b6406  
    168168        assert(!fibril_rcu.registered);
    169169       
    170         _futex_down(&rcu.list_futex);
     170        futex_down(&rcu.list_futex);
    171171        list_append(&fibril_rcu.link, &rcu.fibrils_list);
    172         _futex_up(&rcu.list_futex);
     172        futex_up(&rcu.list_futex);
    173173       
    174174        fibril_rcu.registered = true;
     
    193193        fibril_rcu.nesting_cnt = 0;
    194194       
    195         _futex_down(&rcu.list_futex);
     195        futex_down(&rcu.list_futex);
    196196        list_remove(&fibril_rcu.link);
    197         _futex_up(&rcu.list_futex);
     197        futex_up(&rcu.list_futex);
    198198
    199199        fibril_rcu.registered = false;
     
    330330static void wait_for_readers(size_t reader_group, blocking_mode_t blocking_mode)
    331331{
    332         _futex_down(&rcu.list_futex);
     332        futex_down(&rcu.list_futex);
    333333       
    334334        list_t quiescent_fibrils;
     
    341341                       
    342342                        if (is_preexisting_reader(fib, reader_group)) {
    343                                 _futex_up(&rcu.list_futex);
     343                                futex_up(&rcu.list_futex);
    344344                                sync_sleep(blocking_mode);
    345                                 _futex_down(&rcu.list_futex);
     345                                futex_down(&rcu.list_futex);
    346346                                /* Break to while loop. */
    347347                                break;
     
    354354       
    355355        list_concat(&rcu.fibrils_list, &quiescent_fibrils);
    356         _futex_up(&rcu.list_futex);
     356        futex_up(&rcu.list_futex);
    357357}
    358358
    359359static void lock_sync(blocking_mode_t blocking_mode)
    360360{
    361         _futex_down(&rcu.sync_lock.futex);
     361        futex_down(&rcu.sync_lock.futex);
    362362        if (rcu.sync_lock.locked) {
    363363                if (blocking_mode == BM_BLOCK_FIBRIL) {
     
    369369                        do {
    370370                                blocked_fib.is_ready = false;
    371                                 _futex_up(&rcu.sync_lock.futex);
     371                                futex_up(&rcu.sync_lock.futex);
    372372                                fibril_switch(FIBRIL_TO_MANAGER);
    373                                 _futex_down(&rcu.sync_lock.futex);
     373                                futex_down(&rcu.sync_lock.futex);
    374374                        } while (rcu.sync_lock.locked);
    375375                       
     
    379379                        assert(blocking_mode == BM_BLOCK_THREAD);
    380380                        rcu.sync_lock.blocked_thread_cnt++;
    381                         _futex_up(&rcu.sync_lock.futex);
    382                         _futex_down(&rcu.sync_lock.futex_blocking_threads);
     381                        futex_up(&rcu.sync_lock.futex);
     382                        futex_down(&rcu.sync_lock.futex_blocking_threads);
    383383                }
    384384        } else {
     
    397397        if (0 < rcu.sync_lock.blocked_thread_cnt) {
    398398                --rcu.sync_lock.blocked_thread_cnt;
    399                 _futex_up(&rcu.sync_lock.futex_blocking_threads);
     399                futex_up(&rcu.sync_lock.futex_blocking_threads);
    400400        } else {
    401401                /* Unlock but wake up any fibrils waiting for the lock. */
     
    412412               
    413413                rcu.sync_lock.locked = false;
    414                 _futex_up(&rcu.sync_lock.futex);
     414                futex_up(&rcu.sync_lock.futex);
    415415        }
    416416}
     
    423423         * but keep sync locked.
    424424         */
    425         _futex_up(&rcu.sync_lock.futex);
     425        futex_up(&rcu.sync_lock.futex);
    426426
    427427        if (blocking_mode == BM_BLOCK_FIBRIL) {
     
    431431        }
    432432               
    433         _futex_down(&rcu.sync_lock.futex);
     433        futex_down(&rcu.sync_lock.futex);
    434434}
    435435
Note: See TracChangeset for help on using the changeset viewer.