From 9a22cda9d33378a3b579b329c1a3c1738d8973c2 Mon Sep 17 00:00:00 2001 From: Brett Wilson Date: Wed, 31 Jan 2018 21:05:42 +0000 Subject: [PATCH] Fix GN thread sanitizer bug. Tsan reported that Scope::GetValueWithScope was marking a value as "used" on the same Scope from multiple threads. These sets were all to true so we haven't noticed any stability problems, but we should not be trying to write to scopes across threads. What happens is that a template is created by BUILDCONFIG or a .gni file and called from multiple BUILD.gn files in multiple threads. The scope stored by the template was not marked const, so the derived scopes on each thread were referencing this root closure as mutable and marking variables used in it. This solution is to mark the Scope const. The derived scopes will reference the parent scope as a const and no changes to the shared scope will occur. Change-Id: I0a5026bb2f32b476babab63f479a5d377df410e8 Reviewed-on: https://chromium-review.googlesource.com/890230 Reviewed-by: Dirk Pranke Commit-Queue: Brett Wilson Cr-Commit-Position: refs/heads/master@{#533408} --- tools/gn/template.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/gn/template.h b/tools/gn/template.h index 4e7b3bf9341ef7..6386ba9f2bafd1 100644 --- a/tools/gn/template.h +++ b/tools/gn/template.h @@ -52,7 +52,15 @@ class Template : public base::RefCountedThreadSafe