aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/sync/rwmutex.go23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/sync/rwmutex.go b/src/sync/rwmutex.go
index aafd6a7010..dc0faf6a60 100644
--- a/src/sync/rwmutex.go
+++ b/src/sync/rwmutex.go
@@ -66,21 +66,26 @@ func (rw *RWMutex) RUnlock() {
race.Disable()
}
if r := atomic.AddInt32(&rw.readerCount, -1); r < 0 {
- if r+1 == 0 || r+1 == -rwmutexMaxReaders {
- race.Enable()
- throw("sync: RUnlock of unlocked RWMutex")
- }
- // A writer is pending.
- if atomic.AddInt32(&rw.readerWait, -1) == 0 {
- // The last reader unblocks the writer.
- runtime_Semrelease(&rw.writerSem, false, 0)
- }
+ // Outlined slow-path to allow the fast-path to be inlined
+ rw.rUnlockSlow(r)
}
if race.Enabled {
race.Enable()
}
}
+func (rw *RWMutex) rUnlockSlow(r int32) {
+ if r+1 == 0 || r+1 == -rwmutexMaxReaders {
+ race.Enable()
+ throw("sync: RUnlock of unlocked RWMutex")
+ }
+ // A writer is pending.
+ if atomic.AddInt32(&rw.readerWait, -1) == 0 {
+ // The last reader unblocks the writer.
+ runtime_Semrelease(&rw.writerSem, false, 1)
+ }
+}
+
// Lock locks rw for writing.
// If the lock is already locked for reading or writing,
// Lock blocks until the lock is available.