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

Changeset 5f7d96e in mainline for uspace/lib/c/generic/fibril_synch.c


Ignore:
Timestamp:
2010-12-27T18:18:03Z (11 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master
Children:
43c3937
Parents:
e080332 (diff), e84d65a (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 development

File:
1 edited

Legend:

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

    re080332 r5f7d96e  
    139139static void _fibril_mutex_unlock_unsafe(fibril_mutex_t *fm)
    140140{
    141         assert(fm->counter <= 0);
    142141        if (fm->counter++ < 0) {
    143142                link_t *tmp;
     
    165164void fibril_mutex_unlock(fibril_mutex_t *fm)
    166165{
     166        assert(fibril_mutex_is_locked(fm));
    167167        futex_down(&async_futex);
    168168        _fibril_mutex_unlock_unsafe(fm);
    169169        futex_up(&async_futex);
     170}
     171
     172bool fibril_mutex_is_locked(fibril_mutex_t *fm)
     173{
     174        bool locked = false;
     175       
     176        futex_down(&async_futex);
     177        if (fm->counter <= 0)
     178                locked = true;
     179        futex_up(&async_futex);
     180       
     181        return locked;
    170182}
    171183
     
    230242{
    231243        futex_down(&async_futex);
    232         assert(frw->readers || (frw->writers == 1));
    233244        if (frw->readers) {
    234245                if (--frw->readers) {
     
    296307void fibril_rwlock_read_unlock(fibril_rwlock_t *frw)
    297308{
     309        assert(fibril_rwlock_is_read_locked(frw));
    298310        _fibril_rwlock_common_unlock(frw);
    299311}
     
    301313void fibril_rwlock_write_unlock(fibril_rwlock_t *frw)
    302314{
     315        assert(fibril_rwlock_is_write_locked(frw));
    303316        _fibril_rwlock_common_unlock(frw);
     317}
     318
     319bool fibril_rwlock_is_read_locked(fibril_rwlock_t *frw)
     320{
     321        bool locked = false;
     322
     323        futex_down(&async_futex);
     324        if (frw->readers)
     325                locked = true;
     326        futex_up(&async_futex);
     327
     328        return locked;
     329}
     330
     331bool fibril_rwlock_is_write_locked(fibril_rwlock_t *frw)
     332{
     333        bool locked = false;
     334
     335        futex_down(&async_futex);
     336        if (frw->writers) {
     337                assert(frw->writers == 1);
     338                locked = true;
     339        }
     340        futex_up(&async_futex);
     341
     342        return locked;
     343}
     344
     345bool fibril_rwlock_is_locked(fibril_rwlock_t *frw)
     346{
     347        return fibril_rwlock_is_read_locked(frw) ||
     348            fibril_rwlock_is_write_locked(frw);
    304349}
    305350
     
    314359{
    315360        awaiter_t wdata;
     361
     362        assert(fibril_mutex_is_locked(fm));
    316363
    317364        if (timeout < 0)
Note: See TracChangeset for help on using the changeset viewer.