From 4498afc55b858e856d84925281dbf254a6280efb Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 13 Oct 2016 14:18:27 -0700 Subject: [PATCH] Only register mutators once Mutators are registered into a global variable, and then into the context when it is created. Only call registerMutators once so that the same mutator is not listed multiple times in the global variable when multiple contexts are created. Test: go test -v android/soong/android Change-Id: Ie9e3ed09a89b848462b898476cdfb81a90c64bd3 --- android/register.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/android/register.go b/android/register.go index f869eedea..0ad9d30cb 100644 --- a/android/register.go +++ b/android/register.go @@ -14,7 +14,11 @@ package android -import "github.com/google/blueprint" +import ( + "sync" + + "github.com/google/blueprint" +) type moduleType struct { name string @@ -47,6 +51,8 @@ func RegisterSingletonType(name string, factory blueprint.SingletonFactory) { singletons = append(singletons, singleton{name, factory}) } +var registerMutatorsOnce sync.Once + func NewContext() *blueprint.Context { ctx := blueprint.NewContext() @@ -58,7 +64,7 @@ func NewContext() *blueprint.Context { ctx.RegisterSingletonType(t.name, t.factory) } - registerMutators() + registerMutatorsOnce.Do(registerMutators) for _, t := range mutators { var handle blueprint.MutatorHandle