mirror of
https://github.com/octoleo/syncthing.git
synced 2025-02-02 11:58:28 +00:00
Don't need read lock in files/set
This commit is contained in:
parent
e937e51476
commit
8fe5438b59
14
files/set.go
14
files/set.go
@ -23,7 +23,7 @@ type bitset uint64
|
|||||||
|
|
||||||
type Set struct {
|
type Set struct {
|
||||||
changes map[protocol.NodeID]uint64
|
changes map[protocol.NodeID]uint64
|
||||||
mutex sync.RWMutex
|
mutex sync.Mutex
|
||||||
repo string
|
repo string
|
||||||
db *leveldb.DB
|
db *leveldb.DB
|
||||||
}
|
}
|
||||||
@ -74,8 +74,6 @@ func (s *Set) WithNeed(node protocol.NodeID, fn fileIterator) {
|
|||||||
if debug {
|
if debug {
|
||||||
l.Debugf("%s Need(%v)", s.repo, node)
|
l.Debugf("%s Need(%v)", s.repo, node)
|
||||||
}
|
}
|
||||||
s.mutex.RLock()
|
|
||||||
defer s.mutex.RUnlock()
|
|
||||||
ldbWithNeed(s.db, []byte(s.repo), node[:], fn)
|
ldbWithNeed(s.db, []byte(s.repo), node[:], fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,8 +81,6 @@ func (s *Set) WithHave(node protocol.NodeID, fn fileIterator) {
|
|||||||
if debug {
|
if debug {
|
||||||
l.Debugf("%s WithHave(%v)", s.repo, node)
|
l.Debugf("%s WithHave(%v)", s.repo, node)
|
||||||
}
|
}
|
||||||
s.mutex.RLock()
|
|
||||||
defer s.mutex.RUnlock()
|
|
||||||
ldbWithHave(s.db, []byte(s.repo), node[:], fn)
|
ldbWithHave(s.db, []byte(s.repo), node[:], fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,8 +88,6 @@ func (s *Set) WithGlobal(fn fileIterator) {
|
|||||||
if debug {
|
if debug {
|
||||||
l.Debugf("%s WithGlobal()", s.repo)
|
l.Debugf("%s WithGlobal()", s.repo)
|
||||||
}
|
}
|
||||||
s.mutex.RLock()
|
|
||||||
defer s.mutex.RUnlock()
|
|
||||||
ldbWithGlobal(s.db, []byte(s.repo), fn)
|
ldbWithGlobal(s.db, []byte(s.repo), fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,8 +96,6 @@ func (s *Set) Get(node protocol.NodeID, file string) scanner.File {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Set) GetGlobal(file string) scanner.File {
|
func (s *Set) GetGlobal(file string) scanner.File {
|
||||||
s.mutex.RLock()
|
|
||||||
defer s.mutex.RUnlock()
|
|
||||||
return ldbGetGlobal(s.db, []byte(s.repo), []byte(file))
|
return ldbGetGlobal(s.db, []byte(s.repo), []byte(file))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +104,7 @@ func (s *Set) Availability(file string) []protocol.NodeID {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Set) Changes(node protocol.NodeID) uint64 {
|
func (s *Set) Changes(node protocol.NodeID) uint64 {
|
||||||
s.mutex.RLock()
|
s.mutex.Lock()
|
||||||
defer s.mutex.RUnlock()
|
defer s.mutex.Unlock()
|
||||||
return s.changes[node]
|
return s.changes[node]
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user