diff --git a/cmd/object-api-common.go b/cmd/object-api-common.go index e27131ac6..b5feed0fb 100644 --- a/cmd/object-api-common.go +++ b/cmd/object-api-common.go @@ -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. diff --git a/cmd/routers.go b/cmd/routers.go index 9213f65be..8d386e4fb 100644 --- a/cmd/routers.go +++ b/cmd/routers.go @@ -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.