5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-11-23 00:01:37 +00:00
matterbridge/vendor/layeh.com/gumble/gumble/rpwmutex.go
2020-10-01 22:50:56 +02:00

37 lines
420 B
Go

package gumble
import "sync"
// rpwMutex is a reader-preferred RWMutex.
type rpwMutex struct {
w sync.Mutex
r sync.Mutex
n int
}
func (m *rpwMutex) Lock() {
m.w.Lock()
}
func (m *rpwMutex) Unlock() {
m.w.Unlock()
}
func (m *rpwMutex) RLock() {
m.r.Lock()
m.n++
if m.n == 1 {
m.w.Lock()
}
m.r.Unlock()
}
func (m *rpwMutex) RUnlock() {
m.r.Lock()
m.n--
if m.n == 0 {
m.w.Unlock()
}
m.r.Unlock()
}