MCPcopy
hub / github.com/dropbox/godropbox / processQueue

Method processQueue

sync2/boundedrwlock.go:135–174  ·  view source on GitHub ↗

Walks the queue of eligible waiters (if any) and wakes them (if they're not timed out). Any writer "stops" the walk of the queue.

()

Source from the content-addressed store, hash-verified

133//
134// Any writer "stops" the walk of the queue.
135func (rw *BoundedRWLock) processQueue() {
136
137 if rw.readers != 0 {
138 panic("readers??")
139 }
140
141 if rw.nextWriter != nil {
142 if rw.nextWriter.WakeAtomic() {
143 return
144 }
145 rw.nextWriter = nil
146 }
147
148 for {
149 var next *rwwait
150 select {
151 case next = <-rw.waiters:
152 default:
153 return
154 }
155 if next.writer {
156 // No readers scheduled yet?
157 if rw.readers == 0 {
158 // If they wake up, no one else gets to go
159 if next.WakeAtomic() {
160 rw.nextWriter = next
161 return
162 }
163 } else {
164 rw.nextWriter = next
165 return
166 }
167 } else {
168 // Reader? Let them enter now.
169 if next.WakeAtomic() {
170 rw.readers++
171 }
172 }
173 }
174}
175
176// A waiting entity, writer or reader.
177type rwwait struct {

Callers 2

RUnlockMethod · 0.95
WUnlockMethod · 0.95

Calls 1

WakeAtomicMethod · 0.95

Tested by

no test coverage detected