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

Method RLock

sync2/boundedrwlock.go:42–66  ·  view source on GitHub ↗

Wait for a read lock for up to 'timeout'. Error will be non-nil on timeout or when the wait list is at capacity.

(timeout time.Duration)

Source from the content-addressed store, hash-verified

40//
41// Error will be non-nil on timeout or when the wait list is at capacity.
42func (rw *BoundedRWLock) RLock(timeout time.Duration) (err error) {
43 deadline := time.After(timeout)
44 rw.control.Lock()
45 if rw.nextWriter != nil {
46 me := newWait(false)
47 select {
48 case rw.waiters <- me:
49 default:
50 err = errors.New("Waiter capacity reached in RLock")
51 }
52 rw.control.Unlock()
53 if err != nil {
54 return
55 }
56
57 woken := me.WaitAtomic(deadline)
58 if !woken {
59 return errors.New("Waiter timeout")
60 }
61 } else {
62 rw.readers++
63 rw.control.Unlock()
64 }
65 return
66}
67
68// Unlock a read lock.
69//

Callers 4

TestWriterTimeoutMethod · 0.95
TestReaderTimeoutMethod · 0.95
doTestParallelReadersFunction · 0.95
stressRWMutexFunction · 0.95

Calls 6

NewFunction · 0.92
newWaitFunction · 0.85
WaitAtomicMethod · 0.80
AfterMethod · 0.65
LockMethod · 0.65
UnlockMethod · 0.65

Tested by 4

TestWriterTimeoutMethod · 0.76
TestReaderTimeoutMethod · 0.76
doTestParallelReadersFunction · 0.76
stressRWMutexFunction · 0.76