Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 9ae22ba in mainline


Ignore:
Timestamp:
2009-06-12T17:35:40Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master
Children:
26360f7
Parents:
92d34f0b
Message:

Condition variables for fibrils.

Location:
uspace/lib/libc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/libc/generic/fibril_sync.c

    r92d34f0b r9ae22ba  
    7272}
    7373
    74 void fibril_mutex_unlock(fibril_mutex_t *fm)
    75 {
    76         futex_down(&async_futex);
     74static void _fibril_mutex_unlock_unsafe(fibril_mutex_t *fm)
     75{
    7776        assert(fm->counter <= 0);
    7877        if (fm->counter++ < 0) {
     
    8685                fibril_add_ready((fid_t) f);
    8786        }
     87}
     88
     89void fibril_mutex_unlock(fibril_mutex_t *fm)
     90{
     91        futex_down(&async_futex);
     92        _fibril_mutex_unlock_unsafe(fm);
    8893        futex_up(&async_futex);
    8994}
     
    168173}
    169174
     175void fibril_condvar_initialize(fibril_condvar_t *fcv)
     176{
     177        list_initialize(&fcv->waiters);
     178}
     179
     180void fibril_condvar_wait(fibril_condvar_t *fcv, fibril_mutex_t *fm)
     181{
     182        fibril_t *f = (fibril_t *) fibril_get_id();
     183
     184        futex_down(&async_futex);
     185        list_append(&f->link, &fcv->waiters);
     186        _fibril_mutex_unlock_unsafe(fm);
     187        fibril_switch(FIBRIL_TO_MANAGER);
     188        fibril_mutex_lock(fm);
     189}
     190
     191static void _fibril_condvar_wakeup_common(fibril_condvar_t *fcv, bool once)
     192{
     193        link_t *tmp;
     194        fibril_t *f;
     195
     196        futex_down(&async_futex);
     197        while (!list_empty(&fcv->waiters)) {
     198                tmp = fcv->waiters.next;
     199                f = list_get_instance(tmp, fibril_t, link);
     200                fibril_add_ready((fid_t) f);
     201                if (once)
     202                        break;
     203        }
     204        futex_up(&async_futex);
     205}
     206
     207void fibril_condvar_signal(fibril_condvar_t *fcv)
     208{
     209        _fibril_condvar_wakeup_common(fcv, true);
     210}
     211
     212void fibril_condvar_broadcast(fibril_condvar_t *fcv)
     213{
     214        _fibril_condvar_wakeup_common(fcv, false);
     215}
     216
    170217/** @}
    171218 */
  • uspace/lib/libc/include/fibril_sync.h

    r92d34f0b r9ae22ba  
    7171        }
    7272
     73typedef struct {
     74        link_t waiters;
     75} fibril_condvar_t;
     76
    7377extern void fibril_mutex_initialize(fibril_mutex_t *);
    7478extern void fibril_mutex_lock(fibril_mutex_t *);
     
    8286extern void fibril_rwlock_write_unlock(fibril_rwlock_t *);
    8387
     88extern void fibril_condvar_initialize(fibril_condvar_t *);
     89extern void fibril_condvar_wait(fibril_condvar_t *, fibril_mutex_t *);
     90extern void fibril_condvar_signal(fibril_condvar_t *);
     91extern void fibril_condvar_broadcast(fibril_condvar_t *);
     92
    8493#endif
    8594
Note: See TracChangeset for help on using the changeset viewer.