فهرست منبع

Don't use heap allocated mutexes.

Matt Bolt 1 سال پیش
والد
کامیت
ee86d80fea
2فایلهای تغییر یافته به همراه6 افزوده شده و 9 حذف شده
  1. 5 7
      pkg/config/configfile.go
  2. 1 2
      pkg/config/configmanager.go

+ 5 - 7
pkg/config/configfile.go

@@ -55,9 +55,9 @@ var NoBackingStore error = errors.New("Backing storage does not exist.")
 type ConfigFile struct {
 	store      storage.Storage
 	file       string
-	dataLock   *sync.Mutex
+	dataLock   sync.Mutex
 	data       []byte
-	watchLock  *sync.Mutex
+	watchLock  sync.Mutex
 	watchers   []*pHandler
 	runState   atomic.AtomicRunState
 	lastChange time.Time
@@ -67,11 +67,9 @@ type ConfigFile struct {
 // to the storage.
 func NewConfigFile(store storage.Storage, file string) *ConfigFile {
 	return &ConfigFile{
-		store:     store,
-		file:      file,
-		dataLock:  new(sync.Mutex),
-		data:      nil,
-		watchLock: new(sync.Mutex),
+		store: store,
+		file:  file,
+		data:  nil,
 	}
 }
 

+ 1 - 2
pkg/config/configmanager.go

@@ -46,7 +46,7 @@ func DefaultConfigFileManagerOpts() *ConfigFileManagerOpts {
 // ConfigFileManager is a fascade for a central API used to create and watch
 // config files.
 type ConfigFileManager struct {
-	lock  *sync.Mutex
+	lock  sync.Mutex
 	store storage.Storage
 	files map[string]*ConfigFile
 }
@@ -75,7 +75,6 @@ func NewConfigFileManager(opts *ConfigFileManagerOpts) *ConfigFileManager {
 	}
 
 	return &ConfigFileManager{
-		lock:  new(sync.Mutex),
 		store: configStore,
 		files: make(map[string]*ConfigFile),
 	}