Charles.Forsyth20060303-partialeea662d19 years agoHistory
106 lines · 2.6 KB · Text
RawDownload
.TH QLOCK 10.2.SH NAMEqlock, qunlock, canqlock, rlock, runlock, wlock, wunlock \- serial synchronisation.SH SYNOPSIS.ta \w'\fLvoid 'u.Bvoid	qlock(QLock *l).PP.Bvoid	qunlock(QLock *l).PP.Bint	canqlock(QLock *l).PP.Bvoid	rlock(RWlock *l).PP.Bvoid	runlock(RWlock *l).PP.Bint	canrlock(RWlock *l).PP.Bvoid	wlock(RWlock *l).PP.Bvoid	wunlock(RWlock *l).SH DESCRIPTIONThe primitive locking functions described in.IR lock (10.2)guarantee mutual exclusion, but they implement spin locks,and should not be used if the process might.IR sleep (10.2)within a critical section.The following functions serialise access to a resource by forming an orderlyqueue of processes..PPEach resource to be controlled is given an associated.B QLockstructure; it is usually most straightforward to put the.B QLockin the structure that represents the resource.It must be initialised to zero before use(as guaranteed for global variables and for structures allocated by.IR malloc )..PPOn return from.IR qlock ,the process has acquired the lock.IR l ,and can assume exclusive access to the associated resource.If the lock is not immediately available, the requesting process is placed on aFIFO queue of processes that have requested the lock.Processes on this list are blocked in the.L Queueingstate..PP.I Qunlockunlocks.I land schedules the first process queued for it (if any)..PP.I Canqlockis a non-blocking form of.IR qlock .It tries to obtain the lock.I land returns true if successful, and 0 otherwise;it always returns immediately..PP.B RWlockis a form of lock for resources that have distinct readers and writers.It allows concurrent readers but gives each writer exclusive access.A caller announces its read or write intentions by choice of lock (and unlock) function;the system assumes the caller will not modify a structure accessed under read lock..PP.I Rlockacquires.I lfor reading.The holder can read but agrees not to modify the resource.There may be several concurrent readers..I Canrlockis non-blocking: it returns non-zero if it successfully acquired the lock immediately,and 0 if the resource was unavailable..PP.I Runlockreturns a read lock;the last reader out enables the first writer waiting (if any)..PP.I Wlockacquires a write lock.The holder of such a lock may assume exclusive access to the resource,and is allowed to modify it..PP.I Wunlockreturns a write lock.The next pending process, whether reader or writer, is scheduled..SH SOURCE.B /os/port/qlock.c.br.B /os/emu/port/lock.c.SH SEE ALSO.IR lock (10.2),.IR splhi (10.2)