From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Fri, 23 Aug 1996 18:03:29 -0400 From: philw@plan9.bell-labs.com philw@plan9.bell-labs.com Subject: No subject Topicbox-Message-UUID: 4b739b66-eac8-11e9-9e20-41e7f4b1d025 Message-ID: <19960823220329.eevL9V7Bid8PkNAUmx9jvbigH-nDN-7tefrzVMRQYh8@z> Put this in the library ... philw. #include /* * Multiple readers/Single Write lock package */ void RWlock.Rlock(RWlock *l) { l->x.lock(); /* wait here for writers and exclusion */ l->lock(); l->readers++; l->k.canlock(); /* block writers if we are the first reader */ l->unlock(); l->x.unlock(); } void RWlock.Runlock(RWlock *l) { l->lock(); if(--l->readers == 0) /* last reader out allows writers */ l->k.unlock(); l->unlock(); } void RWlock.Wlock(RWlock *l) { l->x.lock(); /* wait here for writers and exclusion */ l->k.lock(); /* wait here for last reader */ } void RWlock.Wunlock(RWlock *l) { l->k.unlock(); l->x.unlock(); }