From c3c9c4cde5f64f558154f3fca7f8b02e217b5f21 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Tue, 7 Oct 2014 10:34:53 +0200 Subject: [PATCH] Use a separate lock for the subscriber stuff --- internal/config/wrapper.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/internal/config/wrapper.go b/internal/config/wrapper.go index 4c2fd6f8e..e83aac4e3 100644 --- a/internal/config/wrapper.go +++ b/internal/config/wrapper.go @@ -49,8 +49,10 @@ type ConfigWrapper struct { deviceMap map[protocol.DeviceID]DeviceConfiguration folderMap map[string]FolderConfiguration replaces chan Configuration - subs []Handler mut sync.Mutex + + subs []Handler + sMut sync.Mutex } // Wrap wraps an existing Configuration structure and ties it to a file on @@ -84,26 +86,27 @@ func Load(path string, myID protocol.DeviceID) (*ConfigWrapper, error) { // be run manually. func (w *ConfigWrapper) Serve() { for cfg := range w.replaces { - w.mut.Lock() + w.sMut.Lock() subs := w.subs - w.mut.Unlock() + w.sMut.Unlock() for _, h := range subs { h.Changed(cfg) } } } -// Stop stops the Serve() loop. +// Stop stops the Serve() loop. Set and Replace operations will panic after a +// Stop. func (w *ConfigWrapper) Stop() { close(w.replaces) } -// Subscriber registers the given handler to be called on any future +// Subscribe registers the given handler to be called on any future // configuration changes. func (w *ConfigWrapper) Subscribe(h Handler) { - w.mut.Lock() + w.sMut.Lock() w.subs = append(w.subs, h) - w.mut.Unlock() + w.sMut.Unlock() } // Raw returns the currently wrapped Configuration object.