]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
bb/event.py: fire_ui_handlers enable threading lock support
authorAníbal Limón <anibal.limon@linux.intel.com>
Tue, 4 Oct 2016 21:15:56 +0000 (16:15 -0500)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Tue, 4 Oct 2016 23:14:58 +0000 (00:14 +0100)
In some cases there is a need to fire bb events into multiple
python threads so locking is needed (writing to a fd/socket).

Adding a helper functions for disable/enable by request to avoid
overhead.

[YOCTO #10330]

Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
lib/bb/event.py
lib/toaster/tests/functional/README [new file with mode: 0644]

index 42745e241e2dd8145f196f77980fe71db289a608..65b7ebb43bf1bc4f94796d6cc465e74b49615942 100644 (file)
@@ -29,6 +29,8 @@ import logging
 import atexit
 import traceback
 import ast
+import threading
+
 import bb.utils
 import bb.compat
 import bb.exceptions
@@ -68,12 +70,22 @@ _event_handler_map = {}
 _catchall_handlers = {}
 _eventfilter = None
 _uiready = False
+_thread_lock = threading.Lock()
+_thread_lock_enabled = False
 
 if hasattr(__builtins__, '__setitem__'):
     builtins = __builtins__
 else:
     builtins = __builtins__.__dict__
 
+def enable_threadlock():
+    global _thread_lock_enabled
+    _thread_lock_enabled = True
+
+def disable_threadlock():
+    global _thread_lock_enabled
+    _thread_lock_enabled = False
+
 def execute_handler(name, handler, event, d):
     event.data = d
     addedd = False
@@ -146,11 +158,17 @@ def print_ui_queue():
                 logger.handle(event)
 
 def fire_ui_handlers(event, d):
+    global _thread_lock
+    global _thread_lock_enabled
+
     if not _uiready:
         # No UI handlers registered yet, queue up the messages
         ui_queue.append(event)
         return
 
+    if _thread_lock_enabled:
+        _thread_lock.acquire()
+
     errors = []
     for h in _ui_handlers:
         #print "Sending event %s" % event
@@ -169,6 +187,9 @@ def fire_ui_handlers(event, d):
     for h in errors:
         del _ui_handlers[h]
 
+    if _thread_lock_enabled:
+        _thread_lock.release()
+
 def fire(event, d):
     """Fire off an Event"""
 
diff --git a/lib/toaster/tests/functional/README b/lib/toaster/tests/functional/README
new file mode 100644 (file)
index 0000000..e69de29