Changeset 8080262 in mainline


Ignore:
Timestamp:
2018-07-30T18:55:22Z (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:
2965d18
Parents:
b4c8a7b
git-author:
Jiří Zárevúcky <jiri.zarevucky@…> (2018-07-30 18:07:46)
git-committer:
Jiří Zárevúcky <jiri.zarevucky@…> (2018-07-30 18:55:22)
Message:

Replace remaining explicit uses of futex_t outside fibril implementation, and get rid of async_futex.

Location:
uspace/lib/c
Files:
4 edited

Legend:

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

    rb4c8a7b r8080262  
    122122#include "../private/fibril.h"
    123123
     124static FIBRIL_RMUTEX_INITIALIZE(message_mutex);
     125
    124126/** Naming service session */
    125127async_sess_t session_ns;
     
    204206                return;
    205207
    206         futex_lock(&async_futex);
     208        fibril_rmutex_lock(&message_mutex);
    207209
    208210        msg->retval = IPC_GET_RETVAL(*data);
     
    220222        }
    221223
    222         futex_unlock(&async_futex);
     224        fibril_rmutex_unlock(&message_mutex);
    223225}
    224226
     
    390392        assert(!msg->forget);
    391393
    392         futex_lock(&async_futex);
     394        fibril_rmutex_lock(&message_mutex);
    393395
    394396        if (msg->done) {
     
    399401        }
    400402
    401         futex_unlock(&async_futex);
     403        fibril_rmutex_unlock(&message_mutex);
    402404}
    403405
  • uspace/lib/c/generic/async/server.c

    rb4c8a7b r8080262  
    111111#include <errno.h>
    112112#include <sys/time.h>
    113 #include <libarch/barrier.h>
    114113#include <stdbool.h>
    115114#include <stdlib.h>
     
    125124#define DPRINTF(...)  ((void) 0)
    126125
    127 /** Async framework global futex */
    128 futex_t async_futex = FUTEX_INITIALIZER;
    129 
    130126/** Call data */
    131127typedef struct {
     
    250246static sysarg_t notification_avail = 0;
    251247
    252 /* The remaining structures are guarded by async_futex. */
     248static FIBRIL_RMUTEX_INITIALIZE(conn_mutex);
    253249static hash_table_t conn_hash_table;
    254250
     
    430426         * Remove myself from the connection hash table.
    431427         */
    432         futex_lock(&async_futex);
     428        fibril_rmutex_lock(&conn_mutex);
    433429        hash_table_remove(&conn_hash_table, &(conn_key_t){
    434430                .task_id = fibril_connection->in_task_id,
    435431                .phone_hash = fibril_connection->in_phone_hash
    436432        });
    437         futex_unlock(&async_futex);
     433        fibril_rmutex_unlock(&conn_mutex);
    438434
    439435        /*
     
    517513        /* Add connection to the connection hash table */
    518514
    519         futex_lock(&async_futex);
     515        fibril_rmutex_lock(&conn_mutex);
    520516        hash_table_insert(&conn_hash_table, &conn->link);
    521         futex_unlock(&async_futex);
    522 
    523         fibril_add_ready(conn->fid);
     517        fibril_rmutex_unlock(&conn_mutex);
     518
     519        fibril_start(conn->fid);
    524520
    525521        return conn->fid;
     
    618614        assert(call);
    619615
    620         futex_lock(&async_futex);
     616        fibril_rmutex_lock(&conn_mutex);
    621617
    622618        ht_link_t *link = hash_table_find(&conn_hash_table, &(conn_key_t){
     
    625621        });
    626622        if (!link) {
    627                 futex_unlock(&async_futex);
     623                fibril_rmutex_unlock(&conn_mutex);
    628624                return false;
    629625        }
     
    634630        msg_t *msg = malloc(sizeof(*msg));
    635631        if (!msg) {
    636                 futex_unlock(&async_futex);
     632                fibril_rmutex_unlock(&conn_mutex);
    637633                return false;
    638634        }
     
    644640                conn->close_chandle = call->cap_handle;
    645641
     642        fibril_rmutex_unlock(&conn_mutex);
     643
    646644        /* If the connection fibril is waiting for an event, activate it */
    647645        fibril_notify(&conn->msg_arrived);
    648 
    649         futex_unlock(&async_futex);
    650646        return true;
    651647}
     
    960956        }
    961957
    962         futex_lock(&async_futex);
     958        fibril_rmutex_lock(&conn_mutex);
    963959
    964960        /* If nothing in queue, wait until something arrives */
     
    974970                        memset(call, 0, sizeof(ipc_call_t));
    975971                        IPC_SET_IMETHOD(*call, IPC_M_PHONE_HUNGUP);
    976                         futex_unlock(&async_futex);
     972                        fibril_rmutex_unlock(&conn_mutex);
    977973                        return true;
    978974                }
    979975
    980976                // TODO: replace with cvar
    981                 futex_unlock(&async_futex);
     977                fibril_rmutex_unlock(&conn_mutex);
    982978
    983979                errno_t rc = fibril_wait_timeout(&conn->msg_arrived, expires);
     
    985981                        return false;
    986982
    987                 futex_lock(&async_futex);
     983                fibril_rmutex_lock(&conn_mutex);
    988984        }
    989985
     
    995991        free(msg);
    996992
    997         futex_unlock(&async_futex);
     993        fibril_rmutex_unlock(&conn_mutex);
    998994        return true;
    999995}
  • uspace/lib/c/generic/fibril_synch.c

    rb4c8a7b r8080262  
    5353static fibril_local bool deadlocked = false;
    5454
     55static futex_t fibril_synch_futex = FUTEX_INITIALIZER;
     56
    5557typedef struct {
    5658        link_t link;
     
    9698static void check_fibril_for_deadlock(fibril_owner_info_t *oi, fibril_t *fib)
    9799{
    98         futex_assert_is_locked(&async_futex);
     100        futex_assert_is_locked(&fibril_synch_futex);
    99101
    100102        while (oi && oi->owned_by) {
    101103                if (oi->owned_by == fib) {
    102                         futex_unlock(&async_futex);
     104                        futex_unlock(&fibril_synch_futex);
    103105                        print_deadlock(oi);
    104106                        abort();
     
    124126        fibril_t *f = (fibril_t *) fibril_get_id();
    125127
    126         futex_lock(&async_futex);
     128        futex_lock(&fibril_synch_futex);
    127129
    128130        if (fm->counter-- > 0) {
    129131                fm->oi.owned_by = f;
    130                 futex_unlock(&async_futex);
     132                futex_unlock(&fibril_synch_futex);
    131133                return;
    132134        }
     
    137139        f->waits_for = &fm->oi;
    138140
    139         futex_unlock(&async_futex);
     141        futex_unlock(&fibril_synch_futex);
    140142
    141143        fibril_wait_for(&wdata.event);
     
    146148        bool locked = false;
    147149
    148         futex_lock(&async_futex);
     150        futex_lock(&fibril_synch_futex);
    149151        if (fm->counter > 0) {
    150152                fm->counter--;
     
    152154                locked = true;
    153155        }
    154         futex_unlock(&async_futex);
     156        futex_unlock(&fibril_synch_futex);
    155157
    156158        return locked;
     
    177179void fibril_mutex_unlock(fibril_mutex_t *fm)
    178180{
    179         futex_lock(&async_futex);
     181        futex_lock(&fibril_synch_futex);
    180182        _fibril_mutex_unlock_unsafe(fm);
    181         futex_unlock(&async_futex);
     183        futex_unlock(&fibril_synch_futex);
    182184}
    183185
    184186bool fibril_mutex_is_locked(fibril_mutex_t *fm)
    185187{
    186         futex_lock(&async_futex);
     188        futex_lock(&fibril_synch_futex);
    187189        bool locked = (fm->oi.owned_by == (fibril_t *) fibril_get_id());
    188         futex_unlock(&async_futex);
     190        futex_unlock(&fibril_synch_futex);
    189191        return locked;
    190192}
     
    202204        fibril_t *f = (fibril_t *) fibril_get_id();
    203205
    204         futex_lock(&async_futex);
     206        futex_lock(&fibril_synch_futex);
    205207
    206208        if (!frw->writers) {
     
    208210                if (frw->readers++ == 0)
    209211                        frw->oi.owned_by = f;
    210                 futex_unlock(&async_futex);
     212                futex_unlock(&fibril_synch_futex);
    211213                return;
    212214        }
     
    219221        f->waits_for = &frw->oi;
    220222
    221         futex_unlock(&async_futex);
     223        futex_unlock(&fibril_synch_futex);
    222224
    223225        fibril_wait_for(&wdata.event);
     
    228230        fibril_t *f = (fibril_t *) fibril_get_id();
    229231
    230         futex_lock(&async_futex);
     232        futex_lock(&fibril_synch_futex);
    231233
    232234        if (!frw->writers && !frw->readers) {
    233235                frw->oi.owned_by = f;
    234236                frw->writers++;
    235                 futex_unlock(&async_futex);
     237                futex_unlock(&fibril_synch_futex);
    236238                return;
    237239        }
     
    244246        f->waits_for = &frw->oi;
    245247
    246         futex_unlock(&async_futex);
     248        futex_unlock(&fibril_synch_futex);
    247249
    248250        fibril_wait_for(&wdata.event);
     
    306308void fibril_rwlock_read_unlock(fibril_rwlock_t *frw)
    307309{
    308         futex_lock(&async_futex);
     310        futex_lock(&fibril_synch_futex);
    309311        assert(frw->readers > 0);
    310312        _fibril_rwlock_common_unlock(frw);
    311         futex_unlock(&async_futex);
     313        futex_unlock(&fibril_synch_futex);
    312314}
    313315
    314316void fibril_rwlock_write_unlock(fibril_rwlock_t *frw)
    315317{
    316         futex_lock(&async_futex);
     318        futex_lock(&fibril_synch_futex);
    317319        assert(frw->writers == 1);
    318320        assert(frw->oi.owned_by == fibril_self());
    319321        _fibril_rwlock_common_unlock(frw);
    320         futex_unlock(&async_futex);
     322        futex_unlock(&fibril_synch_futex);
    321323}
    322324
    323325bool fibril_rwlock_is_read_locked(fibril_rwlock_t *frw)
    324326{
    325         futex_lock(&async_futex);
     327        futex_lock(&fibril_synch_futex);
    326328        bool locked = (frw->readers > 0);
    327         futex_unlock(&async_futex);
     329        futex_unlock(&fibril_synch_futex);
    328330        return locked;
    329331}
     
    331333bool fibril_rwlock_is_write_locked(fibril_rwlock_t *frw)
    332334{
    333         futex_lock(&async_futex);
     335        futex_lock(&fibril_synch_futex);
    334336        assert(frw->writers <= 1);
    335337        bool locked = (frw->writers > 0) && (frw->oi.owned_by == fibril_self());
    336         futex_unlock(&async_futex);
     338        futex_unlock(&fibril_synch_futex);
    337339        return locked;
    338340}
     
    374376        }
    375377
    376         futex_lock(&async_futex);
     378        futex_lock(&fibril_synch_futex);
    377379        _fibril_mutex_unlock_unsafe(fm);
    378380        list_append(&wdata.link, &fcv->waiters);
    379         futex_unlock(&async_futex);
     381        futex_unlock(&fibril_synch_futex);
    380382
    381383        (void) fibril_wait_timeout(&wdata.event, expires);
    382384
    383         futex_lock(&async_futex);
     385        futex_lock(&fibril_synch_futex);
    384386        bool timed_out = link_in_use(&wdata.link);
    385387        list_remove(&wdata.link);
    386         futex_unlock(&async_futex);
     388        futex_unlock(&fibril_synch_futex);
    387389
    388390        fibril_mutex_lock(fm);
     
    398400void fibril_condvar_signal(fibril_condvar_t *fcv)
    399401{
    400         futex_lock(&async_futex);
     402        futex_lock(&fibril_synch_futex);
    401403
    402404        awaiter_t *w = list_pop(&fcv->waiters, awaiter_t, link);
     
    404406                fibril_notify(&w->event);
    405407
    406         futex_unlock(&async_futex);
     408        futex_unlock(&fibril_synch_futex);
    407409}
    408410
    409411void fibril_condvar_broadcast(fibril_condvar_t *fcv)
    410412{
    411         futex_lock(&async_futex);
     413        futex_lock(&fibril_synch_futex);
    412414
    413415        awaiter_t *w;
     
    415417                fibril_notify(&w->event);
    416418
    417         futex_unlock(&async_futex);
     419        futex_unlock(&fibril_synch_futex);
    418420}
    419421
     
    644646void fibril_semaphore_up(fibril_semaphore_t *sem)
    645647{
    646         futex_lock(&async_futex);
     648        futex_lock(&fibril_synch_futex);
    647649        sem->count++;
    648650
     
    653655        }
    654656
    655         futex_unlock(&async_futex);
     657        futex_unlock(&fibril_synch_futex);
    656658}
    657659
     
    665667void fibril_semaphore_down(fibril_semaphore_t *sem)
    666668{
    667         futex_lock(&async_futex);
     669        futex_lock(&fibril_synch_futex);
    668670        sem->count--;
    669671
    670672        if (sem->count >= 0) {
    671                 futex_unlock(&async_futex);
     673                futex_unlock(&fibril_synch_futex);
    672674                return;
    673675        }
     
    676678        list_append(&wdata.link, &sem->waiters);
    677679
    678         futex_unlock(&async_futex);
     680        futex_unlock(&fibril_synch_futex);
    679681
    680682        fibril_wait_for(&wdata.event);
  • uspace/lib/c/include/ipc/common.h

    rb4c8a7b r8080262  
    5353} ipc_call_t;
    5454
    55 extern futex_t async_futex;
    56 
    5755#endif
    5856
Note: See TracChangeset for help on using the changeset viewer.