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)
| 40 | // |
| 41 | // Error will be non-nil on timeout or when the wait list is at capacity. |
| 42 | func (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 | // |