Changeset 95838f1 in mainline


Ignore:
Timestamp:
2018-06-25T21:45:15Z (6 years ago)
Author:
Jiří Zárevúcky <jiri.zarevucky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
38e3427
Parents:
3679f51a
git-author:
Jiří Zárevúcky <jiri.zarevucky@…> (2018-06-25 20:58:01)
git-committer:
Jiří Zárevúcky <jiri.zarevucky@…> (2018-06-25 21:45:15)
Message:

Switch async_futex to using futex_lock/unlock.

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

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/async/client.c

    r3679f51a r95838f1  
    243243        assert(arg);
    244244
    245         futex_down(&async_futex);
     245        futex_lock(&async_futex);
    246246
    247247        amsg_t *msg = (amsg_t *) arg;
     
    268268        }
    269269
    270         futex_up(&async_futex);
     270        futex_unlock(&async_futex);
    271271}
    272272
     
    357357        amsg_t *msg = (amsg_t *) amsgid;
    358358
    359         futex_down(&async_futex);
     359        futex_lock(&async_futex);
    360360
    361361        assert(!msg->forget);
     
    363363
    364364        if (msg->done) {
    365                 futex_up(&async_futex);
     365                futex_unlock(&async_futex);
    366366                goto done;
    367367        }
     
    403403        amsg_t *msg = (amsg_t *) amsgid;
    404404
    405         futex_down(&async_futex);
     405        futex_lock(&async_futex);
    406406
    407407        assert(!msg->forget);
     
    409409
    410410        if (msg->done) {
    411                 futex_up(&async_futex);
     411                futex_unlock(&async_futex);
    412412                goto done;
    413413        }
     
    477477        assert(!msg->destroyed);
    478478
    479         futex_down(&async_futex);
     479        futex_lock(&async_futex);
    480480
    481481        if (msg->done) {
     
    486486        }
    487487
    488         futex_up(&async_futex);
     488        futex_unlock(&async_futex);
    489489}
    490490
     
    506506        tv_add_diff(&awaiter.to_event.expires, timeout);
    507507
    508         futex_down(&async_futex);
     508        futex_lock(&async_futex);
    509509
    510510        async_insert_timeout(&awaiter);
  • uspace/lib/c/generic/async/server.c

    r3679f51a r95838f1  
    432432         * Remove myself from the connection hash table.
    433433         */
    434         futex_down(&async_futex);
     434        futex_lock(&async_futex);
    435435        hash_table_remove(&conn_hash_table, &(conn_key_t){
    436436                .task_id = fibril_connection->in_task_id,
    437437                .phone_hash = fibril_connection->in_phone_hash
    438438        });
    439         futex_up(&async_futex);
     439        futex_unlock(&async_futex);
    440440
    441441        /*
     
    520520        /* Add connection to the connection hash table */
    521521
    522         futex_down(&async_futex);
     522        futex_lock(&async_futex);
    523523        hash_table_insert(&conn_hash_table, &conn->link);
    524         futex_up(&async_futex);
     524        futex_unlock(&async_futex);
    525525
    526526        fibril_add_ready(conn->wdata.fid);
     
    648648        assert(call);
    649649
    650         futex_down(&async_futex);
     650        futex_lock(&async_futex);
    651651
    652652        ht_link_t *link = hash_table_find(&conn_hash_table, &(conn_key_t){
     
    655655        });
    656656        if (!link) {
    657                 futex_up(&async_futex);
     657                futex_unlock(&async_futex);
    658658                return false;
    659659        }
     
    663663        msg_t *msg = malloc(sizeof(*msg));
    664664        if (!msg) {
    665                 futex_up(&async_futex);
     665                futex_unlock(&async_futex);
    666666                return false;
    667667        }
     
    687687        }
    688688
    689         futex_up(&async_futex);
     689        futex_unlock(&async_futex);
    690690        return true;
    691691}
     
    962962        connection_t *conn = fibril_connection;
    963963
    964         futex_down(&async_futex);
     964        futex_lock(&async_futex);
    965965
    966966        if (usecs) {
     
    982982                        memset(call, 0, sizeof(ipc_call_t));
    983983                        IPC_SET_IMETHOD(*call, IPC_M_PHONE_HUNGUP);
    984                         futex_up(&async_futex);
     984                        futex_unlock(&async_futex);
    985985                        return conn->close_chandle;
    986986                }
     
    10031003                 * Get it again.
    10041004                 */
    1005                 futex_down(&async_futex);
     1005                futex_lock(&async_futex);
    10061006                if ((usecs) && (conn->wdata.to_event.occurred) &&
    10071007                    (list_empty(&conn->msg_queue))) {
    10081008                        /* If we timed out -> exit */
    1009                         futex_up(&async_futex);
     1009                        futex_unlock(&async_futex);
    10101010                        return CAP_NIL;
    10111011                }
     
    10201020        free(msg);
    10211021
    1022         futex_up(&async_futex);
     1022        futex_unlock(&async_futex);
    10231023        return chandle;
    10241024}
     
    11061106        getuptime(&tv);
    11071107
    1108         futex_down(&async_futex);
     1108        futex_lock(&async_futex);
    11091109
    11101110        link_t *cur = list_first(&timeout_list);
     
    11321132        }
    11331133
    1134         futex_up(&async_futex);
     1134        futex_unlock(&async_futex);
    11351135}
    11361136
     
    11441144        while (true) {
    11451145                if (fibril_switch(FIBRIL_FROM_MANAGER)) {
    1146                         futex_up(&async_futex);
     1146                        futex_unlock(&async_futex);
    11471147                        /*
    11481148                         * async_futex is always held when entering a manager
     
    11521152                }
    11531153
    1154                 futex_down(&async_futex);
     1154                futex_lock(&async_futex);
    11551155
    11561156                suseconds_t timeout;
     
    11641164
    11651165                        if (tv_gteq(&tv, &waiter->to_event.expires)) {
    1166                                 futex_up(&async_futex);
     1166                                futex_unlock(&async_futex);
    11671167                                handle_expired_timeouts();
    11681168                                /*
     
    11821182                                timeout = tv_sub_diff(&waiter->to_event.expires,
    11831183                                    &tv);
    1184                                 futex_up(&async_futex);
     1184                                futex_unlock(&async_futex);
    11851185                        }
    11861186                } else {
    1187                         futex_up(&async_futex);
     1187                        futex_unlock(&async_futex);
    11881188                        timeout = SYNCH_NO_TIMEOUT;
    11891189                }
     
    12261226static errno_t async_manager_fibril(void *arg)
    12271227{
    1228         futex_up(&async_futex);
     1228        futex_unlock(&async_futex);
    12291229
    12301230        /*
     
    18871887_Noreturn void async_manager(void)
    18881888{
    1889         futex_down(&async_futex);
     1889        futex_lock(&async_futex);
    18901890        fibril_switch(FIBRIL_FROM_DEAD);
    18911891        __builtin_unreachable();
  • uspace/lib/c/generic/fibril.c

    r3679f51a r95838f1  
    7979        fibril->retval = fibril->func(fibril->arg);
    8080
    81         futex_down(&async_futex);
     81        futex_lock(&async_futex);
    8282        fibril_switch(FIBRIL_FROM_DEAD);
    8383        /* Not reached */
  • uspace/lib/c/generic/fibril_synch.c

    r3679f51a r95838f1  
    106106        fibril_t *f = (fibril_t *) fibril_get_id();
    107107
    108         futex_down(&async_futex);
     108        futex_lock(&async_futex);
    109109        if (fm->counter-- <= 0) {
    110110                awaiter_t wdata;
     
    119119        } else {
    120120                fm->oi.owned_by = f;
    121                 futex_up(&async_futex);
     121                futex_unlock(&async_futex);
    122122        }
    123123}
     
    127127        bool locked = false;
    128128
    129         futex_down(&async_futex);
     129        futex_lock(&async_futex);
    130130        if (fm->counter > 0) {
    131131                fm->counter--;
     
    133133                locked = true;
    134134        }
    135         futex_up(&async_futex);
     135        futex_unlock(&async_futex);
    136136
    137137        return locked;
     
    166166{
    167167        assert(fibril_mutex_is_locked(fm));
    168         futex_down(&async_futex);
     168        futex_lock(&async_futex);
    169169        _fibril_mutex_unlock_unsafe(fm);
    170         futex_up(&async_futex);
     170        futex_unlock(&async_futex);
    171171}
    172172
     
    175175        bool locked = false;
    176176
    177         futex_down(&async_futex);
     177        futex_lock(&async_futex);
    178178        if (fm->counter <= 0)
    179179                locked = true;
    180         futex_up(&async_futex);
     180        futex_unlock(&async_futex);
    181181
    182182        return locked;
     
    195195        fibril_t *f = (fibril_t *) fibril_get_id();
    196196
    197         futex_down(&async_futex);
     197        futex_lock(&async_futex);
    198198        if (frw->writers) {
    199199                awaiter_t wdata;
     
    211211                if (frw->readers++ == 0)
    212212                        frw->oi.owned_by = f;
    213                 futex_up(&async_futex);
     213                futex_unlock(&async_futex);
    214214        }
    215215}
     
    219219        fibril_t *f = (fibril_t *) fibril_get_id();
    220220
    221         futex_down(&async_futex);
     221        futex_lock(&async_futex);
    222222        if (frw->writers || frw->readers) {
    223223                awaiter_t wdata;
     
    234234                frw->oi.owned_by = f;
    235235                frw->writers++;
    236                 futex_up(&async_futex);
     236                futex_unlock(&async_futex);
    237237        }
    238238}
     
    240240static void _fibril_rwlock_common_unlock(fibril_rwlock_t *frw)
    241241{
    242         futex_down(&async_futex);
     242        futex_lock(&async_futex);
    243243        if (frw->readers) {
    244244                if (--frw->readers) {
     
    301301        }
    302302out:
    303         futex_up(&async_futex);
     303        futex_unlock(&async_futex);
    304304}
    305305
     
    320320        bool locked = false;
    321321
    322         futex_down(&async_futex);
     322        futex_lock(&async_futex);
    323323        if (frw->readers)
    324324                locked = true;
    325         futex_up(&async_futex);
     325        futex_unlock(&async_futex);
    326326
    327327        return locked;
     
    332332        bool locked = false;
    333333
    334         futex_down(&async_futex);
     334        futex_lock(&async_futex);
    335335        if (frw->writers) {
    336336                assert(frw->writers == 1);
    337337                locked = true;
    338338        }
    339         futex_up(&async_futex);
     339        futex_unlock(&async_futex);
    340340
    341341        return locked;
     
    369369        wdata.wu_event.inlist = true;
    370370
    371         futex_down(&async_futex);
     371        futex_lock(&async_futex);
    372372        if (timeout) {
    373373                getuptime(&wdata.to_event.expires);
     
    381381
    382382        /* async_futex not held after fibril_switch() */
    383         futex_down(&async_futex);
     383        futex_lock(&async_futex);
    384384        if (wdata.to_event.inlist)
    385385                list_remove(&wdata.to_event.link);
    386386        if (wdata.wu_event.inlist)
    387387                list_remove(&wdata.wu_event.link);
    388         futex_up(&async_futex);
     388        futex_unlock(&async_futex);
    389389
    390390        return wdata.to_event.occurred ? ETIMEOUT : EOK;
     
    404404        awaiter_t *wdp;
    405405
    406         futex_down(&async_futex);
     406        futex_lock(&async_futex);
    407407        while (!list_empty(&fcv->waiters)) {
    408408                tmp = list_first(&fcv->waiters);
     
    418418                }
    419419        }
    420         futex_up(&async_futex);
     420        futex_unlock(&async_futex);
    421421}
    422422
     
    657657void fibril_semaphore_up(fibril_semaphore_t *sem)
    658658{
    659         futex_down(&async_futex);
     659        futex_lock(&async_futex);
    660660        sem->count++;
    661661
    662662        if (sem->count > 0) {
    663                 futex_up(&async_futex);
     663                futex_unlock(&async_futex);
    664664                return;
    665665        }
     
    669669        list_remove(tmp);
    670670
    671         futex_up(&async_futex);
     671        futex_unlock(&async_futex);
    672672
    673673        awaiter_t *wdp = list_get_instance(tmp, awaiter_t, wu_event.link);
     
    685685void fibril_semaphore_down(fibril_semaphore_t *sem)
    686686{
    687         futex_down(&async_futex);
     687        futex_lock(&async_futex);
    688688        sem->count--;
    689689
    690690        if (sem->count >= 0) {
    691                 futex_up(&async_futex);
     691                futex_unlock(&async_futex);
    692692                return;
    693693        }
Note: See TracChangeset for help on using the changeset viewer.