3 qlock, qunlock, canqlock, rlock, runlock, wlock, wunlock \- serial synchronisation
13 Lock use; /* to access Qlock structure */
14 Proc *head; /* next process waiting for object */
15 Proc *tail; /* last process waiting for object */
16 int locked; /* flag */
22 Proc *head; /* list of waiting processes */
24 uintptr wpc; /* pc of writer */
25 Proc *wproc; /* writing proc */
26 int readers; /* number of readers */
27 int writer; /* number of writers */
38 void qunlock(QLock *l)
41 int canqlock(QLock *l)
47 void runlock(RWlock *l)
50 int canrlock(RWlock *l)
56 void wunlock(RWlock *l)
58 The primitive locking functions described in
60 guarantee mutual exclusion, but they implement spin locks,
61 and should not be used if the process might
63 within a critical section.
64 The following functions serialise access to a resource by forming an orderly
67 Each resource to be controlled is given an associated
69 structure; it is usually most straightforward to put the
71 in the structure that represents the resource.
72 It must be initialised to zero before use
73 (as guaranteed for global variables and for structures allocated by
78 the process has acquired the lock
80 and can assume exclusive access to the associated resource.
81 If the lock is not immediately available, the requesting process is placed on a
82 FIFO queue of processes that have requested the lock.
83 Processes on this list are blocked in the
88 is an interruptible form of
94 and schedules the first process queued for it (if any).
97 is a non-blocking form of
99 It tries to obtain the lock
101 and returns true if successful, and 0 otherwise;
102 it always returns immediately.
105 is a form of lock for resources that have distinct readers and writers.
106 It allows concurrent readers but gives each writer exclusive access.
107 A caller announces its read or write intentions by choice of lock (and unlock) function;
108 the system assumes the caller will not modify a structure accessed under read lock.
114 The holder can read but agrees not to modify the resource.
115 There may be several concurrent readers.
117 is non-blocking: it returns non-zero if it successfully acquired the lock immediately,
118 and 0 if the resource was unavailable.
122 the last reader out enables the first writer waiting (if any).
125 acquires a write lock.
126 The holder of such a lock may assume exclusive access to the resource,
127 and is allowed to modify it.
130 returns a write lock.
131 The next pending process, whether reader or writer, is scheduled.
133 .B /sys/src/9/port/qlock.c