tpl/images: Fix embedded sync.Mutex

This commit is contained in:
Cameron Moore authored and Bjørn Erik Pedersen committed 2017-05-02 09:17:14 +02:00
1 parent f69df916df
commit f604076de1
2 files changed
+6 -36

No files matched your search

-30
View File
@@ -727,36 +727,6 @@
"imageConfig" "imageConfig"
], ],
"Examples": [] "Examples": []
},
{
"Name": "Lock",
"Description": "",
"Aliases": null,
"Examples": null
},
{
"Name": "RLock",
"Description": "",
"Aliases": null,
"Examples": null
},
{
"Name": "RLocker",
"Description": "",
"Aliases": null,
"Examples": null
},
{
"Name": "RUnlock",
"Description": "",
"Aliases": null,
"Examples": null
},
{
"Name": "Unlock",
"Description": "",
"Aliases": null,
"Examples": null
} }
] ]
}, },
+6 -6
View File
@@ -37,8 +37,8 @@ func New(deps *deps.Deps) *Namespace {
// Namespace provides template functions for the "images" namespace. // Namespace provides template functions for the "images" namespace.
type Namespace struct { type Namespace struct {
sync.RWMutex cacheMu sync.RWMutex
cache map[string]image.Config cache map[string]image.Config
deps *deps.Deps deps *deps.Deps
} }
@@ -56,9 +56,9 @@ func (ns *Namespace) Config(path interface{}) (image.Config, error) {
} }
// Check cache for image config. // Check cache for image config.
ns.RLock() ns.cacheMu.RLock()
config, ok := ns.cache[filename] config, ok := ns.cache[filename]
ns.RUnlock() ns.cacheMu.RUnlock()
if ok { if ok {
return config, nil return config, nil
@@ -71,9 +71,9 @@ func (ns *Namespace) Config(path interface{}) (image.Config, error) {
config, _, err = image.DecodeConfig(f) config, _, err = image.DecodeConfig(f)
ns.Lock() ns.cacheMu.Lock()
ns.cache[filename] = config ns.cache[filename] = config
ns.Unlock() ns.cacheMu.Unlock()
return config, err return config, err
} }