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

Unified Diff: gft_common.py

Issue 6822028: factory_test_tools: improve gft_hwcomp (hardware_Components) performance (Closed) Base URL: ssh://gitrw.chromium.org:9222/factory_test_tools.git@master
Patch Set: add comments for why isolateing EC 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') | gft_hwcomp.py » ('J')
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 ed2c52c626de979000dcc03a3725c7348b742b2a..5f93ab8559f5b15c025623759385a56b144bede7 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') | gft_hwcomp.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698