image: Improve store locking
Brian Goff authored on 2017/06/22 02:01:19... | ... |
@@ -37,7 +37,7 @@ type imageMeta struct { |
37 | 37 |
} |
38 | 38 |
|
39 | 39 |
type store struct { |
40 |
- sync.Mutex |
|
40 |
+ sync.RWMutex |
|
41 | 41 |
ls LayerGetReleaser |
42 | 42 |
images map[ID]*imageMeta |
43 | 43 |
fs StoreBackend |
... | ... |
@@ -166,9 +166,6 @@ func (is *store) Create(config []byte) (ID, error) { |
166 | 166 |
} |
167 | 167 |
|
168 | 168 |
func (is *store) Search(term string) (ID, error) { |
169 |
- is.Lock() |
|
170 |
- defer is.Unlock() |
|
171 |
- |
|
172 | 169 |
dgst, err := is.digestSet.Lookup(term) |
173 | 170 |
if err != nil { |
174 | 171 |
if err == digestset.ErrDigestNotFound { |
... | ... |
@@ -251,8 +248,8 @@ func (is *store) GetParent(id ID) (ID, error) { |
251 | 251 |
} |
252 | 252 |
|
253 | 253 |
func (is *store) Children(id ID) []ID { |
254 |
- is.Lock() |
|
255 |
- defer is.Unlock() |
|
254 |
+ is.RLock() |
|
255 |
+ defer is.RUnlock() |
|
256 | 256 |
|
257 | 257 |
return is.children(id) |
258 | 258 |
} |
... | ... |
@@ -276,8 +273,8 @@ func (is *store) Map() map[ID]*Image { |
276 | 276 |
} |
277 | 277 |
|
278 | 278 |
func (is *store) imagesMap(all bool) map[ID]*Image { |
279 |
- is.Lock() |
|
280 |
- defer is.Unlock() |
|
279 |
+ is.RLock() |
|
280 |
+ defer is.RUnlock() |
|
281 | 281 |
|
282 | 282 |
images := make(map[ID]*Image) |
283 | 283 |
|