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

Unified Diff: gft_common.py

Issue 6839009: factory_test_tools: merge latest improvements from ToT to R12 factory branch (Closed) Base URL: ssh://gitrw.chromium.org:9222/factory_test_tools.git@0.12.369.B
Patch Set: Created 9 years, 8 months 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 | « no previous file | gft_hwcomp.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gft_common.py
diff --git a/gft_common.py b/gft_common.py
index 1fbbb237cfc3c3a433fd436cbe00188b5edd165f..1c65c464f2433b5612152f1f7d8f86fd9da8afdd 100644
--- a/gft_common.py
+++ b/gft_common.py
@@ -14,6 +14,7 @@ import os
import subprocess
import sys
import tempfile
+import threading
import time
@@ -214,6 +215,32 @@ def WriteFile(filename, data):
opened_file.write(data)
+def ThreadSafe(f):
+ """ Decorator for functions that need synchronoization. """
+ lock = threading.Lock()
+ def threadsafe_call(*args):
+ try:
+ lock.acquire()
+ return f(*args)
+ finally:
+ lock.release()
+ return threadsafe_call
+
+
+def Memorize(f):
+ """ Decorator for functions that need memorization. """
+ memorize_data = {}
+ def memorize_call(*args):
+ index = repr(args)
+ if index in memorize_data:
+ value = memorize_data[index]
+ # DebugMsg('Memorize: using cached value for: %s %s' % (repr(f), index))
+ return value
+ value = f(*args)
+ memorize_data[index] = value
+ return value
+ return memorize_call
+
########################################################################
# Components Databases
« no previous file with comments | « no previous file | gft_hwcomp.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698