From 2764839ae1ccc55e08d6290ecbf7b58d837bbdd2 Mon Sep 17 00:00:00 2001 From: Brian Goff Date: Sat, 7 Nov 2015 21:23:12 -0500 Subject: [PATCH] Replace `imageMutex` with `Locker` pkg Signed-off-by: Brian Goff --- graph/graph.go | 3 ++- graph/mutex.go | 45 --------------------------------------------- 2 files changed, 2 insertions(+), 46 deletions(-) delete mode 100644 graph/mutex.go diff --git a/graph/graph.go b/graph/graph.go index 56b44a79f0..0fedee0b7f 100644 --- a/graph/graph.go +++ b/graph/graph.go @@ -22,6 +22,7 @@ import ( "github.com/docker/docker/image" "github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/idtools" + "github.com/docker/docker/pkg/locker" "github.com/docker/docker/pkg/progressreader" "github.com/docker/docker/pkg/streamformatter" "github.com/docker/docker/pkg/stringid" @@ -100,7 +101,7 @@ type Graph struct { idIndex *truncindex.TruncIndex driver graphdriver.Driver imagesMutex sync.Mutex - imageMutex imageMutex // protect images in driver. + imageMutex locker.Locker // protect images in driver. retained *retainedLayers tarSplitDisabled bool uidMaps []idtools.IDMap diff --git a/graph/mutex.go b/graph/mutex.go deleted file mode 100644 index a5f3991bba..0000000000 --- a/graph/mutex.go +++ /dev/null @@ -1,45 +0,0 @@ -package graph - -import "sync" - -// imageMutex provides a lock per image id to protect shared resources in the -// graph. This is only used with registration but should be used when -// manipulating the layer store. -type imageMutex struct { - mus map[string]*sync.Mutex // mutexes by image id. - mu sync.Mutex // protects lock map - - // NOTE(stevvooe): The map above will grow to the size of all images ever - // registered during a daemon run. To free these resources, we must - // deallocate after unlock. Doing this safely is non-trivial in the face - // of a very minor leak. -} - -// Lock the provided id. -func (im *imageMutex) Lock(id string) { - im.getImageLock(id).Lock() -} - -// Unlock the provided id. -func (im *imageMutex) Unlock(id string) { - im.getImageLock(id).Unlock() -} - -// getImageLock returns the mutex for the given id. This method will never -// return nil. -func (im *imageMutex) getImageLock(id string) *sync.Mutex { - im.mu.Lock() - defer im.mu.Unlock() - - if im.mus == nil { // lazy - im.mus = make(map[string]*sync.Mutex) - } - - mu, ok := im.mus[id] - if !ok { - mu = new(sync.Mutex) - im.mus[id] = mu - } - - return mu -}