Ignore:
Timestamp:
2019-02-01T22:30:53Z (6 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Parents:
1a37496
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2019-02-01 22:12:04)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2019-02-01 22:30:53)
Message:

Change the meaning of counter in fibril mutex

Previously analogous to semaphore tokens, initially 1 and
counting downward into negative numbers.

Now the number of fibrils currently accessing or waiting for access
to the critical sections. Initially 0 (unlocked mutex), and counting
up. Never negative when used correctly. Also consistent with
readers/writers counts in rwlock.

This way is IMO easier to understand.

File:
1 edited

Legend:

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

    r1a37496 r3ede440  
    165165{
    166166        fm->oi.owned_by = NULL;
    167         fm->counter = 1;
     167        fm->counter = 0;
    168168        list_initialize(&fm->waiters);
    169169}
     
    175175        futex_lock(&fibril_synch_futex);
    176176
    177         if (fm->counter-- > 0) {
     177        fm->counter++;
     178
     179        if (fm->counter == 1) {
     180                /* I am the only one here. */
    178181                fm->oi.owned_by = f;
    179182                futex_unlock(&fibril_synch_futex);
     
    196199
    197200        futex_lock(&fibril_synch_futex);
    198         if (fm->counter > 0) {
    199                 fm->counter--;
     201        if (fm->counter == 0) {
     202                fm->counter++;
    200203                fm->oi.owned_by = (fibril_t *) fibril_get_id();
    201204                locked = true;
     
    209212{
    210213        assert(fm->oi.owned_by == (fibril_t *) fibril_get_id());
    211 
    212         if (fm->counter++ < 0) {
     214        assert(fm->counter > 0);
     215
     216        fm->counter--;
     217
     218        if (fm->counter > 0) {
    213219                awaiter_t *wdp = list_pop(&fm->waiters, awaiter_t, link);
    214220                assert(wdp);
Note: See TracChangeset for help on using the changeset viewer.