File tree Expand file tree Collapse file tree 2 files changed +27
-9
lines changed Expand file tree Collapse file tree 2 files changed +27
-9
lines changed Original file line number Diff line number Diff line change @@ -66,21 +66,26 @@ func (rw *RWMutex) RUnlock() {
66
66
race .Disable ()
67
67
}
68
68
if r := atomic .AddInt32 (& rw .readerCount , - 1 ); r < 0 {
69
- if r + 1 == 0 || r + 1 == - rwmutexMaxReaders {
70
- race .Enable ()
71
- throw ("sync: RUnlock of unlocked RWMutex" )
72
- }
73
- // A writer is pending.
74
- if atomic .AddInt32 (& rw .readerWait , - 1 ) == 0 {
75
- // The last reader unblocks the writer.
76
- runtime_Semrelease (& rw .writerSem , false , 0 )
77
- }
69
+ // Outlined slow-path to allow the fast-path to be inlined
70
+ rw .rUnlockSlow (r )
78
71
}
79
72
if race .Enabled {
80
73
race .Enable ()
81
74
}
82
75
}
83
76
77
+ func (rw * RWMutex ) rUnlockSlow (r int32 ) {
78
+ if r + 1 == 0 || r + 1 == - rwmutexMaxReaders {
79
+ race .Enable ()
80
+ throw ("sync: RUnlock of unlocked RWMutex" )
81
+ }
82
+ // A writer is pending.
83
+ if atomic .AddInt32 (& rw .readerWait , - 1 ) == 0 {
84
+ // The last reader unblocks the writer.
85
+ runtime_Semrelease (& rw .writerSem , false , 1 )
86
+ }
87
+ }
88
+
84
89
// Lock locks rw for writing.
85
90
// If the lock is already locked for reading or writing,
86
91
// Lock blocks until the lock is available.
Original file line number Diff line number Diff line change @@ -38,3 +38,16 @@ func small7() { // ERROR "can inline small7"
38
38
// the Do fast path should be inlined
39
39
once .Do (small5 ) // ERROR "inlining call to sync\.\(\*Once\)\.Do" "&sync\.o\.done escapes to heap"
40
40
}
41
+
42
+ var rwmutex * sync.RWMutex
43
+
44
+ func small8 () { // ERROR "can inline small8"
45
+ // the RUnlock fast path should be inlined
46
+ rwmutex .RUnlock () // ERROR "inlining call to sync\.\(\*RWMutex\)\.RUnlock" "&sync\.rw\.readerCount escapes to heap"
47
+ }
48
+
49
+ func small9 () { // ERROR "can inline small9"
50
+ // the RLock fast path should be inlined
51
+ rwmutex .RLock () // ERROR "inlining call to sync\.\(\*RWMutex\)\.RLock" "&sync\.rw\.readerCount escapes to heap" "&sync\.rw\.readerSem escapes to heap"
52
+ }
53
+
You can’t perform that action at this time.
0 commit comments