use RW mutexes in marksets

This commit is contained in:
vyzo 2021-07-08 10:20:29 +03:00
parent 48f13a43b7
commit e6eacbdd56
2 changed files with 6 additions and 6 deletions

View File

@ -24,7 +24,7 @@ var _ MarkSetEnv = (*BloomMarkSetEnv)(nil)
type BloomMarkSet struct {
salt []byte
mx sync.Mutex
mx sync.RWMutex
bf *bbloom.Bloom
ts bool
}
@ -84,8 +84,8 @@ func (s *BloomMarkSet) Mark(cid cid.Cid) error {
func (s *BloomMarkSet) Has(cid cid.Cid) (bool, error) {
if s.ts {
s.mx.Lock()
defer s.mx.Unlock()
s.mx.RLock()
defer s.mx.RUnlock()
}
if s.bf == nil {

View File

@ -13,7 +13,7 @@ type MapMarkSetEnv struct {
var _ MarkSetEnv = (*MapMarkSetEnv)(nil)
type MapMarkSet struct {
mx sync.Mutex
mx sync.RWMutex
set map[string]struct{}
ts bool
@ -52,8 +52,8 @@ func (s *MapMarkSet) Mark(cid cid.Cid) error {
func (s *MapMarkSet) Has(cid cid.Cid) (bool, error) {
if s.ts {
s.mx.Lock()
defer s.mx.Unlock()
s.mx.RLock()
defer s.mx.RUnlock()
}
if s.set == nil {