Skip to content

Commit 5a3c195

Browse files
committed
add RWMutex
1 parent 610425a commit 5a3c195

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

sync.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ func (lock *mutexInfo) wait() (int32, *list.Element) {
4848
}
4949

5050
lock.verify(holder, []*mutexInfo{lock})
51-
5251
return holder, lock.waiting.PushBack(holder)
5352
}
5453

@@ -79,7 +78,6 @@ func (lock *mutexInfo) using(holder int32, elem *list.Element) {
7978
defer lockMutex.Unlock()
8079

8180
delete(waitTargets, holder)
82-
8381
atomic.StoreInt32(&lock.holder, holder)
8482
lock.waiting.Remove(elem)
8583
}
@@ -111,3 +109,23 @@ func (m *Mutex) Unlock() {
111109
}
112110
m.Mutex.Unlock()
113111
}
112+
113+
type RWMutex struct {
114+
Mutex
115+
}
116+
117+
func (rw *RWMutex) Lock() {
118+
rw.Lock()
119+
}
120+
121+
func (rw *RWMutex) Unlock() {
122+
rw.Unlock()
123+
}
124+
125+
func (rw *RWMutex) RLock() {
126+
rw.Lock()
127+
}
128+
129+
func (rw *RWMutex) RUnlock() {
130+
rw.Unlock()
131+
}

0 commit comments

Comments
 (0)