Make BottomUpMutators parallel
Append .Parallel() to all of the RegisterBottomUpMutator calls to tell
Blueprint it can run them in parallel.
Test: identical build.ninja, passes race detector
Change-Id: I969a0689522d4cba7c8ff51e2aa00fe2fd338a89
diff --git a/cc/cc.go b/cc/cc.go
index 6698007..752046f 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -38,17 +38,17 @@
// LinkageMutator must be registered after common.ArchMutator, but that is guaranteed by
// the Go initialization order because this package depends on common, so common's init
// functions will run first.
- android.RegisterBottomUpMutator("link", linkageMutator)
- android.RegisterBottomUpMutator("ndk_api", ndkApiMutator)
- android.RegisterBottomUpMutator("test_per_src", testPerSrcMutator)
- android.RegisterBottomUpMutator("begin", beginMutator)
- android.RegisterBottomUpMutator("deps", depsMutator)
+ android.RegisterBottomUpMutator("link", linkageMutator).Parallel()
+ android.RegisterBottomUpMutator("ndk_api", ndkApiMutator).Parallel()
+ android.RegisterBottomUpMutator("test_per_src", testPerSrcMutator).Parallel()
+ android.RegisterBottomUpMutator("begin", beginMutator).Parallel()
+ android.RegisterBottomUpMutator("deps", depsMutator).Parallel()
android.RegisterTopDownMutator("asan_deps", sanitizerDepsMutator(asan))
- android.RegisterBottomUpMutator("asan", sanitizerMutator(asan))
+ android.RegisterBottomUpMutator("asan", sanitizerMutator(asan)).Parallel()
android.RegisterTopDownMutator("tsan_deps", sanitizerDepsMutator(tsan))
- android.RegisterBottomUpMutator("tsan", sanitizerMutator(tsan))
+ android.RegisterBottomUpMutator("tsan", sanitizerMutator(tsan)).Parallel()
pctx.Import("android/soong/cc/config")
}
diff --git a/cc/ndk_library.go b/cc/ndk_library.go
index fe52b0e..b0fd398 100644
--- a/cc/ndk_library.go
+++ b/cc/ndk_library.go
@@ -18,6 +18,7 @@
"fmt"
"strconv"
"strings"
+ "sync"
"github.com/google/blueprint"
@@ -58,7 +59,8 @@
// These libraries have migrated over to the new ndk_library, which is added
// as a variation dependency via depsMutator.
- ndkMigratedLibs = []string{}
+ ndkMigratedLibs = []string{}
+ ndkMigratedLibsLock sync.Mutex // protects ndkMigratedLibs writes during parallel beginMutator
)
// Creates a stub shared library based on the provided version file.
@@ -177,6 +179,8 @@
c.baseCompiler.compilerInit(ctx)
name := strings.TrimSuffix(ctx.ModuleName(), ".ndk")
+ ndkMigratedLibsLock.Lock()
+ defer ndkMigratedLibsLock.Unlock()
for _, lib := range ndkMigratedLibs {
if lib == name {
return