-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlock.go
More file actions
61 lines (49 loc) · 767 Bytes
/
Copy pathlock.go
File metadata and controls
61 lines (49 loc) · 767 Bytes
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
package eutil
import "sync"
type Mutex struct {
mu sync.RWMutex
}
func (m *Mutex) Lock() {
m.mu.Lock()
}
func (m *Mutex) Unlock() {
m.mu.Unlock()
}
func (m *Mutex) RLock() {
m.mu.RLock()
}
func (m *Mutex) RUnlock() {
m.mu.RUnlock()
}
func (m *Mutex) TryLock() bool {
return m.mu.TryLock()
}
func (m *Mutex) TryRLock() bool {
return m.mu.TryRLock()
}
func (m *Mutex) WithLock(f func()) {
m.Lock()
defer m.Unlock()
f()
}
func (m *Mutex) WithRLock(f func()) {
m.mu.RLock()
defer m.mu.RUnlock()
f()
}
func (m *Mutex) WithTryLock(f func()) bool {
if m.TryLock() {
defer m.Unlock()
f()
return true
}
return false
}
func (m *Mutex) WithTryRLock(f func()) bool {
if m.TryRLock() {
defer m.RUnlock()
f()
return true
}
return false
}