aboutsummaryrefslogtreecommitdiffstats
path: root/common/config.go
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2015-04-15 12:33:28 -0700
committerColin Cross <ccross@android.com>2015-04-15 12:41:44 -0700
commitc1e86a389610e83f977b7f1835ba1a203e3d656f (patch)
tree0b138d32f0354294b301c59590814ba582b53ce9 /common/config.go
parentc215ca203e7e13f085740edb31a732c19b00610e (diff)
downloadbuild_soong-c1e86a389610e83f977b7f1835ba1a203e3d656f.tar.gz
build_soong-c1e86a389610e83f977b7f1835ba1a203e3d656f.tar.bz2
build_soong-c1e86a389610e83f977b7f1835ba1a203e3d656f.zip
Fix race condition in config.Getenv
The envDeps map may be accessed concurrently by multiple modules in GenerateBuildActions, wrap the accesses in a mutex. Change-Id: I18abf2687997c045a99b987908623f7d8c2ea344
Diffstat (limited to 'common/config.go')
-rw-r--r--common/config.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/common/config.go b/common/config.go
index a6837c13..5d761e66 100644
--- a/common/config.go
+++ b/common/config.go
@@ -20,6 +20,7 @@ import (
"os"
"path/filepath"
"runtime"
+ "sync"
)
// The configuration file name
@@ -44,6 +45,8 @@ type config struct {
FileConfigurableOptions
srcDir string // the path of the root source directory
+
+ envLock sync.Mutex
envDeps map[string]string
}
@@ -166,10 +169,12 @@ func (c *config) CpPreserveSymlinksFlags() string {
func (c *config) Getenv(key string) string {
var val string
var exists bool
+ c.envLock.Lock()
if val, exists = c.envDeps[key]; !exists {
val = os.Getenv(key)
c.envDeps[key] = val
}
+ c.envLock.Unlock()
return val
}