gooftool: Should use double-checked locking
Gooftool tries to maintain only one global instance
to achieve the effect like the Singleton pattern.
To implement this correctly, it should doubly check
the instance, since the global singleton instance
might be created from another thread after the first
checking statement.
BUG=none
TEST=make test
Change-Id: Id726106117ded67a514154f5c3c8a609c483ecba
Reviewed-on: https://chromium-review.googlesource.com/601695
Commit-Ready: Shen-En Shih <petershih@chromium.org>
Tested-by: Shen-En Shih <petershih@chromium.org>
Reviewed-by: Hung-Te Lin <hungte@chromium.org>
diff --git a/py/gooftool/commands.py b/py/gooftool/commands.py
index 2fc9980..25ced64 100755
--- a/py/gooftool/commands.py
+++ b/py/gooftool/commands.py
@@ -64,10 +64,11 @@
if _global_gooftool is None:
with _gooftool_lock:
- project = getattr(options, 'project', None)
- hwdb_path = getattr(options, 'hwdb_path', None)
- _global_gooftool = Gooftool(hwid_version=3, project=project,
- hwdb_path=hwdb_path)
+ if _global_gooftool is None:
+ project = getattr(options, 'project', None)
+ hwdb_path = getattr(options, 'hwdb_path', None)
+ _global_gooftool = Gooftool(hwid_version=3, project=project,
+ hwdb_path=hwdb_path)
return _global_gooftool