Signed-off-by: Brian Goff <cpuguy83@gmail.com>
| ... | ... |
@@ -22,6 +22,7 @@ import ( |
| 22 | 22 |
"github.com/docker/docker/image" |
| 23 | 23 |
"github.com/docker/docker/pkg/archive" |
| 24 | 24 |
"github.com/docker/docker/pkg/idtools" |
| 25 |
+ "github.com/docker/docker/pkg/locker" |
|
| 25 | 26 |
"github.com/docker/docker/pkg/progressreader" |
| 26 | 27 |
"github.com/docker/docker/pkg/streamformatter" |
| 27 | 28 |
"github.com/docker/docker/pkg/stringid" |
| ... | ... |
@@ -100,7 +101,7 @@ type Graph struct {
|
| 100 | 100 |
idIndex *truncindex.TruncIndex |
| 101 | 101 |
driver graphdriver.Driver |
| 102 | 102 |
imagesMutex sync.Mutex |
| 103 |
- imageMutex imageMutex // protect images in driver. |
|
| 103 |
+ imageMutex locker.Locker // protect images in driver. |
|
| 104 | 104 |
retained *retainedLayers |
| 105 | 105 |
tarSplitDisabled bool |
| 106 | 106 |
uidMaps []idtools.IDMap |
| 107 | 107 |
deleted file mode 100644 |
| ... | ... |
@@ -1,45 +0,0 @@ |
| 1 |
-package graph |
|
| 2 |
- |
|
| 3 |
-import "sync" |
|
| 4 |
- |
|
| 5 |
-// imageMutex provides a lock per image id to protect shared resources in the |
|
| 6 |
-// graph. This is only used with registration but should be used when |
|
| 7 |
-// manipulating the layer store. |
|
| 8 |
-type imageMutex struct {
|
|
| 9 |
- mus map[string]*sync.Mutex // mutexes by image id. |
|
| 10 |
- mu sync.Mutex // protects lock map |
|
| 11 |
- |
|
| 12 |
- // NOTE(stevvooe): The map above will grow to the size of all images ever |
|
| 13 |
- // registered during a daemon run. To free these resources, we must |
|
| 14 |
- // deallocate after unlock. Doing this safely is non-trivial in the face |
|
| 15 |
- // of a very minor leak. |
|
| 16 |
-} |
|
| 17 |
- |
|
| 18 |
-// Lock the provided id. |
|
| 19 |
-func (im *imageMutex) Lock(id string) {
|
|
| 20 |
- im.getImageLock(id).Lock() |
|
| 21 |
-} |
|
| 22 |
- |
|
| 23 |
-// Unlock the provided id. |
|
| 24 |
-func (im *imageMutex) Unlock(id string) {
|
|
| 25 |
- im.getImageLock(id).Unlock() |
|
| 26 |
-} |
|
| 27 |
- |
|
| 28 |
-// getImageLock returns the mutex for the given id. This method will never |
|
| 29 |
-// return nil. |
|
| 30 |
-func (im *imageMutex) getImageLock(id string) *sync.Mutex {
|
|
| 31 |
- im.mu.Lock() |
|
| 32 |
- defer im.mu.Unlock() |
|
| 33 |
- |
|
| 34 |
- if im.mus == nil { // lazy
|
|
| 35 |
- im.mus = make(map[string]*sync.Mutex) |
|
| 36 |
- } |
|
| 37 |
- |
|
| 38 |
- mu, ok := im.mus[id] |
|
| 39 |
- if !ok {
|
|
| 40 |
- mu = new(sync.Mutex) |
|
| 41 |
- im.mus[id] = mu |
|
| 42 |
- } |
|
| 43 |
- |
|
| 44 |
- return mu |
|
| 45 |
-} |