-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrwmutex.go
65 lines (57 loc) · 1.11 KB
/
rwmutex.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package detectlock
import (
"reflect"
"sync"
)
// Mutex wrapped from sync.RWMutex
type RWMutex struct {
rwm sync.RWMutex
}
func (l *RWMutex) RLock() {
if debug {
lockerPtr := reflect.ValueOf(l).Pointer()
acquire(lockerPtr, true, l.rwm.RLock)
} else {
l.rwm.RLock()
}
}
func (l *RWMutex) TryRLock() bool {
if debug {
lockerPtr := reflect.ValueOf(l).Pointer()
return tryAcquire(lockerPtr, true, l.rwm.TryRLock)
} else {
return l.rwm.TryRLock()
}
}
func (l *RWMutex) RUnlock() {
if debug {
lockerPtr := reflect.ValueOf(l).Pointer()
release(lockerPtr, true, l.rwm.RUnlock)
} else {
l.rwm.RUnlock()
}
}
func (l *RWMutex) Lock() {
if debug {
lockerPtr := reflect.ValueOf(l).Pointer()
acquire(lockerPtr, false, l.rwm.Lock)
} else {
l.rwm.Lock()
}
}
func (l *RWMutex) TryLock() bool {
if debug {
lockerPtr := reflect.ValueOf(l).Pointer()
return tryAcquire(lockerPtr, false, l.rwm.TryLock)
} else {
return l.rwm.TryLock()
}
}
func (l *RWMutex) Unlock() {
if debug {
lockerPtr := reflect.ValueOf(l).Pointer()
release(lockerPtr, false, l.rwm.Unlock)
} else {
l.rwm.Unlock()
}
}