فهرست منبع

We don't need a separate subscription lock

We forgot to lock it during replace, so data rate. This is simpler.
Jakob Borg 10 سال پیش
والد
کامیت
bd0e97023e
1فایلهای تغییر یافته به همراه5 افزوده شده و 8 حذف شده
  1. 5 8
      lib/config/wrapper.go

+ 5 - 8
lib/config/wrapper.go

@@ -60,10 +60,8 @@ type Wrapper struct {
 	deviceMap map[protocol.DeviceID]DeviceConfiguration
 	folderMap map[string]FolderConfiguration
 	replaces  chan Configuration
+	subs      []Committer
 	mut       sync.Mutex
-
-	subs []Committer
-	sMut sync.Mutex
 }
 
 // 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,
 		path: path,
 		mut:  sync.NewMutex(),
-		sMut: sync.NewMutex(),
 	}
 	w.replaces = make(chan Configuration)
 	return w
@@ -109,15 +106,15 @@ func (w *Wrapper) Stop() {
 // Subscribe registers the given handler to be called on any future
 // configuration changes.
 func (w *Wrapper) Subscribe(c Committer) {
-	w.sMut.Lock()
+	w.mut.Lock()
 	w.subs = append(w.subs, c)
-	w.sMut.Unlock()
+	w.mut.Unlock()
 }
 
 // Unsubscribe de-registers the given handler from any future calls to
 // configuration changes
 func (w *Wrapper) Unsubscribe(c Committer) {
-	w.sMut.Lock()
+	w.mut.Lock()
 	for i := range w.subs {
 		if w.subs[i] == c {
 			copy(w.subs[i:], w.subs[i+1:])
@@ -126,7 +123,7 @@ func (w *Wrapper) Unsubscribe(c Committer) {
 			break
 		}
 	}
-	w.sMut.Unlock()
+	w.mut.Unlock()
 }
 
 // Raw returns the currently wrapped Configuration object.