summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/event.py
diff options
context:
space:
mode:
authorAníbal Limón <anibal.limon@linux.intel.com>2016-10-04 16:15:56 -0500
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-10-05 10:10:11 +0100
commit79012f943d3b3af1f439022f05a1287a383cd3f8 (patch)
tree441da4ddfb3263f60ee24e012e0400624e9d03dd /bitbake/lib/bb/event.py
parent45f401abe59978b822e6198186ac5cd8c75d56ee (diff)
downloadpoky-79012f943d3b3af1f439022f05a1287a383cd3f8.tar.gz
bitbake: bb/event.py: fire_ui_handlers enable threading lock support
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] (Bitbake rev: a583dc0b296415ec904c081c4de96ceef46732a8) Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/event.py')
-rw-r--r--bitbake/lib/bb/event.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/bitbake/lib/bb/event.py b/bitbake/lib/bb/event.py
index 42745e241e..65b7ebb43b 100644
--- a/bitbake/lib/bb/event.py
+++ b/bitbake/lib/bb/event.py
@@ -29,6 +29,8 @@ import logging
29import atexit 29import atexit
30import traceback 30import traceback
31import ast 31import ast
32import threading
33
32import bb.utils 34import bb.utils
33import bb.compat 35import bb.compat
34import bb.exceptions 36import bb.exceptions
@@ -68,12 +70,22 @@ _event_handler_map = {}
68_catchall_handlers = {} 70_catchall_handlers = {}
69_eventfilter = None 71_eventfilter = None
70_uiready = False 72_uiready = False
73_thread_lock = threading.Lock()
74_thread_lock_enabled = False
71 75
72if hasattr(__builtins__, '__setitem__'): 76if hasattr(__builtins__, '__setitem__'):
73 builtins = __builtins__ 77 builtins = __builtins__
74else: 78else:
75 builtins = __builtins__.__dict__ 79 builtins = __builtins__.__dict__
76 80
81def enable_threadlock():
82 global _thread_lock_enabled
83 _thread_lock_enabled = True
84
85def disable_threadlock():
86 global _thread_lock_enabled
87 _thread_lock_enabled = False
88
77def execute_handler(name, handler, event, d): 89def execute_handler(name, handler, event, d):
78 event.data = d 90 event.data = d
79 addedd = False 91 addedd = False
@@ -146,11 +158,17 @@ def print_ui_queue():
146 logger.handle(event) 158 logger.handle(event)
147 159
148def fire_ui_handlers(event, d): 160def fire_ui_handlers(event, d):
161 global _thread_lock
162 global _thread_lock_enabled
163
149 if not _uiready: 164 if not _uiready:
150 # No UI handlers registered yet, queue up the messages 165 # No UI handlers registered yet, queue up the messages
151 ui_queue.append(event) 166 ui_queue.append(event)
152 return 167 return
153 168
169 if _thread_lock_enabled:
170 _thread_lock.acquire()
171
154 errors = [] 172 errors = []
155 for h in _ui_handlers: 173 for h in _ui_handlers:
156 #print "Sending event %s" % event 174 #print "Sending event %s" % event
@@ -169,6 +187,9 @@ def fire_ui_handlers(event, d):
169 for h in errors: 187 for h in errors:
170 del _ui_handlers[h] 188 del _ui_handlers[h]
171 189
190 if _thread_lock_enabled:
191 _thread_lock.release()
192
172def fire(event, d): 193def fire(event, d):
173 """Fire off an Event""" 194 """Fire off an Event"""
174 195