1
0
mirror of https://github.com/charlienet/go-mixed.git synced 2025-07-18 00:22:41 +08:00
This commit is contained in:
2024-05-28 04:17:26 +08:00
parent 822932fe15
commit 1abde30d8f
4 changed files with 12 additions and 30 deletions

View File

@ -1,14 +1,9 @@
package locker package locker
var _ RWLocker = &emptyLocker{} var _ rwLocker = &emptyLocker{}
var _ Locker = &emptyLocker{} var _ locker = &emptyLocker{}
var EmptyLocker = &emptyLocker{} type emptyLocker struct {
type emptyLocker struct{}
func NewEmptyLocker() *emptyLocker {
return &emptyLocker{}
} }
func (l *emptyLocker) RLock() {} func (l *emptyLocker) RLock() {}

View File

@ -2,14 +2,16 @@ package locker
import "sync" import "sync"
type Locker interface { type locker interface {
Lock() Lock()
Unlock() Unlock()
TryLock() bool TryLock() bool
} }
type RWLocker interface { type rwLocker interface {
Locker Lock()
Unlock()
TryLock() bool
RLock() RLock()
RUnlock() RUnlock()
TryRLock() bool TryRLock() bool
@ -18,3 +20,7 @@ type RWLocker interface {
func NewLocker() *sync.Mutex { func NewLocker() *sync.Mutex {
return &sync.Mutex{} return &sync.Mutex{}
} }
func NewRWLocker() *sync.RWMutex {
return &sync.RWMutex{}
}

View File

@ -1,7 +0,0 @@
package locker
import "sync"
func NewRWLocker() *sync.RWMutex {
return &sync.RWMutex{}
}

View File

@ -1,12 +0,0 @@
package locker
import "testing"
func TestRWLokcer(t *testing.T) {
l := NewRWLocker()
l.RLock()
t.Log(l.TryRLock())
l.RUnlock()
}