Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Unified Diff: build/android/devil/utils/lazy/weak_constant.py

Issue 1416703003: [Android] Add a configurable environment for devil/. (RELAND 2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/android/devil/utils/lazy/__init__.py ('k') | build/android/devil/utils/lsusb.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/devil/utils/lazy/weak_constant.py
diff --git a/build/android/devil/utils/lazy/weak_constant.py b/build/android/devil/utils/lazy/weak_constant.py
new file mode 100644
index 0000000000000000000000000000000000000000..3558f29ac6722dda01fb6c5892653cd96446f7f0
--- /dev/null
+++ b/build/android/devil/utils/lazy/weak_constant.py
@@ -0,0 +1,29 @@
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import threading
+
+
+class WeakConstant(object):
+ """A thread-safe, lazily initialized object.
+
+ This does not support modification after initialization. The intended
+ constant nature of the object is not enforced, though, hence the "weak".
+ """
+
+ def __init__(self, initializer):
+ self._initialized = False
+ self._initializer = initializer
+ self._lock = threading.Lock()
+ self._val = None
+
+ def read(self):
+ """Get the object, creating it if necessary."""
+ if self._initialized:
+ return self._val
+ with self._lock:
+ if not self._initialized:
+ self._val = self._initializer()
+ self._initialized = True
+ return self._val
« no previous file with comments | « build/android/devil/utils/lazy/__init__.py ('k') | build/android/devil/utils/lsusb.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698