Skip to content

Commit 5c6aae7

Browse files
committed
fix RWMutex bug
1 parent 6ee36e1 commit 5c6aae7

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

deadlock.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,27 @@ func (m *Mutex) Unlock() {
2727
}
2828

2929
type RWMutex struct {
30-
Mutex
30+
monitor
31+
sync.RWMutex
3132
}
3233

33-
func (rw *RWMutex) Lock() {
34-
rw.Lock()
34+
func (m *RWMutex) Lock() {
35+
waitInfo := m.monitor.wait()
36+
m.RWMutex.Lock()
37+
m.monitor.using(waitInfo)
3538
}
3639

37-
func (rw *RWMutex) Unlock() {
38-
rw.Unlock()
40+
func (m *RWMutex) Unlock() {
41+
m.monitor.release()
42+
m.RWMutex.Unlock()
3943
}
4044

41-
func (rw *RWMutex) RLock() {
42-
rw.Lock()
45+
func (m *RWMutex) RLock() {
46+
m.RWMutex.RLock()
4347
}
4448

45-
func (rw *RWMutex) RUnlock() {
46-
rw.Unlock()
49+
func (m *RWMutex) RUnlock() {
50+
m.RWMutex.RUnlock()
4751
}
4852

4953
var (

0 commit comments

Comments
 (0)