mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-22 22:58:25 +00:00
We don't need a separate subscription lock
We forgot to lock it during replace, so data rate. This is simpler.
This commit is contained in:
parent
34ff0706a3
commit
bd0e97023e
@ -60,10 +60,8 @@ type Wrapper struct {
|
|||||||
deviceMap map[protocol.DeviceID]DeviceConfiguration
|
deviceMap map[protocol.DeviceID]DeviceConfiguration
|
||||||
folderMap map[string]FolderConfiguration
|
folderMap map[string]FolderConfiguration
|
||||||
replaces chan Configuration
|
replaces chan Configuration
|
||||||
|
subs []Committer
|
||||||
mut sync.Mutex
|
mut sync.Mutex
|
||||||
|
|
||||||
subs []Committer
|
|
||||||
sMut sync.Mutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wrap wraps an existing Configuration structure and ties it to a file on
|
// Wrap wraps an existing Configuration structure and ties it to a file on
|
||||||
@ -73,7 +71,6 @@ func Wrap(path string, cfg Configuration) *Wrapper {
|
|||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
path: path,
|
path: path,
|
||||||
mut: sync.NewMutex(),
|
mut: sync.NewMutex(),
|
||||||
sMut: sync.NewMutex(),
|
|
||||||
}
|
}
|
||||||
w.replaces = make(chan Configuration)
|
w.replaces = make(chan Configuration)
|
||||||
return w
|
return w
|
||||||
@ -109,15 +106,15 @@ func (w *Wrapper) Stop() {
|
|||||||
// Subscribe registers the given handler to be called on any future
|
// Subscribe registers the given handler to be called on any future
|
||||||
// configuration changes.
|
// configuration changes.
|
||||||
func (w *Wrapper) Subscribe(c Committer) {
|
func (w *Wrapper) Subscribe(c Committer) {
|
||||||
w.sMut.Lock()
|
w.mut.Lock()
|
||||||
w.subs = append(w.subs, c)
|
w.subs = append(w.subs, c)
|
||||||
w.sMut.Unlock()
|
w.mut.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unsubscribe de-registers the given handler from any future calls to
|
// Unsubscribe de-registers the given handler from any future calls to
|
||||||
// configuration changes
|
// configuration changes
|
||||||
func (w *Wrapper) Unsubscribe(c Committer) {
|
func (w *Wrapper) Unsubscribe(c Committer) {
|
||||||
w.sMut.Lock()
|
w.mut.Lock()
|
||||||
for i := range w.subs {
|
for i := range w.subs {
|
||||||
if w.subs[i] == c {
|
if w.subs[i] == c {
|
||||||
copy(w.subs[i:], w.subs[i+1:])
|
copy(w.subs[i:], w.subs[i+1:])
|
||||||
@ -126,7 +123,7 @@ func (w *Wrapper) Unsubscribe(c Committer) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
w.sMut.Unlock()
|
w.mut.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Raw returns the currently wrapped Configuration object.
|
// Raw returns the currently wrapped Configuration object.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user