[Piglit] [PATCH 1/3] framework.log: Replace synchronized_self decorator

Dylan Baker baker.dylan.c at gmail.com
Tue Apr 1 10:12:54 PDT 2014


This replaces the synchronized_self decorator from piglit's threading
module with the standard python syntax

with lock:
    <stuff>

Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
---
 framework/log.py | 37 +++++++++++++++++++------------------
 1 file changed, 19 insertions(+), 18 deletions(-)

diff --git a/framework/log.py b/framework/log.py
index 2835f1e..9d1f55f 100644
--- a/framework/log.py
+++ b/framework/log.py
@@ -22,7 +22,7 @@
 
 import sys
 import collections
-from .threads import synchronized_self
+from threading import RLock
 
 
 class Log(object):
@@ -38,6 +38,7 @@ class Log(object):
         self.__running = []
         self.__generator = (x for x in xrange(self.__total))
         self.__pad = len(str(self.__total))
+        self.__lock = RLock()
         self.__summary_keys = set(['pass', 'fail', 'warn', 'crash', 'skip',
                                    'dmesg-warn', 'dmesg-fail', 'dry-run'])
         self.__summary = collections.defaultdict(lambda: 0)
@@ -74,7 +75,6 @@ class Log(object):
         # newline.
         sys.stdout.flush()
 
-    @synchronized_self
     def post_log(self, value, result):
         """ Used to mark a test as complete in the log
 
@@ -83,17 +83,17 @@ class Log(object):
         result -- the result of the completed test
 
         """
-        # Mark running complete
-        assert value in self.__running
-        self.__running.remove(value)
+        with self.__lock:
+            # Mark running complete
+            assert value in self.__running
+            self.__running.remove(value)
 
-        # increment the number of completed tests
-        self.__complete += 1
+            # increment the number of completed tests
+            self.__complete += 1
 
-        assert result in self.__summary_keys
-        self.__summary[result] += 1
+            assert result in self.__summary_keys
+            self.__summary[result] += 1
 
-    @synchronized_self
     def log(self, name, result):
         """ Print to the screen 
 
@@ -101,10 +101,10 @@ class Log(object):
         over it.
 
         """
-        assert result in self.__summary_keys
-        self.__print(name, result)
+        with self.__lock:
+            assert result in self.__summary_keys
+            self.__print(name, result)
 
-    @synchronized_self
     def pre_log(self, running=None):
         """ Hook to run before log()
         
@@ -116,9 +116,10 @@ class Log(object):
                    nothing will be printed. Default: None
         
         """
-        if running:
-            self.__print(running, 'running')
+        with self.__lock:
+            if running:
+                self.__print(running, 'running')
 
-        x = self.__generator.next()
-        self.__running.append(x)
-        return x
+            x = self.__generator.next()
+            self.__running.append(x)
+            return x
-- 
1.9.1



More information about the Piglit mailing list