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

Changeset 9414abc in mainline for uspace/lib/c/generic/fibril_synch.c


Ignore:
Timestamp:
2010-11-06T09:58:51Z (11 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master
Children:
1712f87, 32efd86
Parents:
55bd76c
Message:

Add deadlock detection for cases when the rwlock is owned by only one reader.
Associate the rwlock ownership with the first reader so that the detection works
at least partially even if the lock is owned by multiple readers. The ownership
information is not passed onto the remaining readers when the owner unlocks the
lock.

File:
1 edited

Legend:

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

    r55bd76c r9414abc  
    180180void fibril_rwlock_read_lock(fibril_rwlock_t *frw)
    181181{
     182        fibril_t *f = (fibril_t *) fibril_get_id();
     183       
    182184        futex_down(&async_futex);
    183185        if (frw->writers) {
    184                 fibril_t *f = (fibril_t *) fibril_get_id();
    185186                awaiter_t wdata;
    186187
     
    195196                fibril_switch(FIBRIL_TO_MANAGER);
    196197        } else {
    197                 frw->readers++;
     198                /* Consider the first reader the owner. */
     199                if (frw->readers++ == 0)
     200                        frw->oi.owned_by = f;
    198201                futex_up(&async_futex);
    199202        }
     
    229232        assert(frw->readers || (frw->writers == 1));
    230233        if (frw->readers) {
    231                 if (--frw->readers)
     234                if (--frw->readers) {
     235                        if (frw->oi.owned_by == (fibril_t *) fibril_get_id()) {
     236                                /*
     237                                 * If this reader firbril was considered the
     238                                 * owner of this rwlock, clear the ownership
     239                                 * information even if there are still more
     240                                 * readers.
     241                                 *
     242                                 * This is the limitation of the detection
     243                                 * mechanism rooted in the fact that tracking
     244                                 * all readers would require dynamically
     245                                 * allocated memory for keeping linkage info.
     246                                 */
     247                                frw->oi.owned_by = NULL;
     248                        }
    232249                        goto out;
     250                }
    233251        } else {
    234252                frw->writers--;
     
    265283                        list_remove(&wdp->wu_event.link);
    266284                        fibril_add_ready(wdp->fid);
    267                         frw->readers++;
     285                        if (frw->readers++ == 0) {
     286                                /* Consider the first reader the owner. */
     287                                frw->oi.owned_by = f;
     288                        }
    268289                        optimize_execution_power();
    269290                }
Note: See TracChangeset for help on using the changeset viewer.