diff options
Diffstat (limited to 'libgo/go/text/template/template.go')
-rw-r--r-- | libgo/go/text/template/template.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/libgo/go/text/template/template.go b/libgo/go/text/template/template.go index ec26eb4..fd74d45 100644 --- a/libgo/go/text/template/template.go +++ b/libgo/go/text/template/template.go @@ -13,6 +13,7 @@ import ( // common holds the information shared by related templates. type common struct { tmpl map[string]*Template // Map from name to defined templates. + muTmpl sync.RWMutex // protects tmpl option option // We use two maps, one for parsing and one for execution. // This separation makes the API cleaner since it doesn't @@ -88,6 +89,8 @@ func (t *Template) Clone() (*Template, error) { if t.common == nil { return nt, nil } + t.muTmpl.RLock() + defer t.muTmpl.RUnlock() for k, v := range t.tmpl { if k == t.name { nt.tmpl[t.name] = nt @@ -124,6 +127,8 @@ func (t *Template) copy(c *common) *Template { // its definition. If it has been defined and already has that name, the existing // definition is replaced; otherwise a new template is created, defined, and returned. func (t *Template) AddParseTree(name string, tree *parse.Tree) (*Template, error) { + t.muTmpl.Lock() + defer t.muTmpl.Unlock() t.init() nt := t if name != t.name { @@ -142,6 +147,8 @@ func (t *Template) Templates() []*Template { return nil } // Return a slice so we don't expose the map. + t.muTmpl.RLock() + defer t.muTmpl.RUnlock() m := make([]*Template, 0, len(t.tmpl)) for _, v := range t.tmpl { m = append(m, v) @@ -182,6 +189,8 @@ func (t *Template) Lookup(name string) *Template { if t.common == nil { return nil } + t.muTmpl.RLock() + defer t.muTmpl.RUnlock() return t.tmpl[name] } |