1
0
mirror of https://github.com/charlienet/go-mixed.git synced 2025-07-18 16:42:41 +08:00

2 Commits

Author SHA1 Message Date
1abde30d8f locker 2024-05-28 04:17:26 +08:00
822932fe15 use base locker 2024-05-28 04:14:08 +08:00
5 changed files with 15 additions and 33 deletions

View File

@ -2,15 +2,15 @@ package bloom
import ( import (
"context" "context"
"sync"
"github.com/bits-and-blooms/bitset" "github.com/bits-and-blooms/bitset"
"github.com/charlienet/go-mixed/locker"
) )
type memStore struct { type memStore struct {
size uint size uint
set *bitset.BitSet // 内存位图 set *bitset.BitSet // 内存位图
lock locker.RWLocker // 同步锁 lock sync.RWMutex // 同步锁
} }
func newMemStore(size uint) *memStore { func newMemStore(size uint) *memStore {

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()
}