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

Changeset b0a76d5 in mainline


Ignore:
Timestamp:
2010-12-21T15:23:31Z (11 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master
Children:
c81b6f2
Parents:
be942bc
Message:

Add interfaces for partial enforcement of locking protocols in userspace:

  • fibril_mutex_is_locked()
  • fibril_rwlock_is_read_locked()
  • fibril_rwlock_is_write_locked()
Location:
uspace/lib/c
Files:
2 edited

Legend:

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

    rbe942bc rb0a76d5  
    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;
    304343}
    305344
     
    314353{
    315354        awaiter_t wdata;
     355
     356        assert(fibril_mutex_is_locked(fm));
    316357
    317358        if (timeout < 0)
  • uspace/lib/c/include/fibril_synch.h

    rbe942bc rb0a76d5  
    105105extern bool fibril_mutex_trylock(fibril_mutex_t *);
    106106extern void fibril_mutex_unlock(fibril_mutex_t *);
     107extern bool fibril_mutex_is_locked(fibril_mutex_t *);
    107108
    108109extern void fibril_rwlock_initialize(fibril_rwlock_t *);
     
    111112extern void fibril_rwlock_read_unlock(fibril_rwlock_t *);
    112113extern void fibril_rwlock_write_unlock(fibril_rwlock_t *);
     114extern bool fibril_rwlock_is_read_locked(fibril_rwlock_t *);
     115extern bool fibril_rwlock_is_write_locked(fibril_rwlock_t *);
    113116
    114117extern void fibril_condvar_initialize(fibril_condvar_t *);
Note: See TracChangeset for help on using the changeset viewer.