Enhanced newObjectLayerFn (#3837)

This commit is contained in:
Zejun Li 2017-03-03 17:07:45 +08:00 committed by Harshavardhana
parent 98d17d2a97
commit 32d0d3d4ac
2 changed files with 7 additions and 6 deletions

View File

@ -38,14 +38,14 @@ const (
)
// Global object layer mutex, used for safely updating object layer.
var globalObjLayerMutex *sync.Mutex
var globalObjLayerMutex *sync.RWMutex
// Global object layer, only accessed by newObjectLayerFn().
var globalObjectAPI ObjectLayer
func init() {
// Initialize this once per server initialization.
globalObjLayerMutex = &sync.Mutex{}
globalObjLayerMutex = &sync.RWMutex{}
}
// Check if the disk is remote.

View File

@ -22,10 +22,11 @@ import (
router "github.com/gorilla/mux"
)
func newObjectLayerFn() ObjectLayer {
globalObjLayerMutex.Lock()
defer globalObjLayerMutex.Unlock()
return globalObjectAPI
func newObjectLayerFn() (layer ObjectLayer) {
globalObjLayerMutex.RLock()
layer = globalObjectAPI
globalObjLayerMutex.RUnlock()
return
}
// Composed function registering routers for only distributed XL setup.