diff options
author | Aníbal Limón <anibal.limon@linux.intel.com> | 2016-10-04 16:15:56 -0500 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-10-05 10:10:11 +0100 |
commit | 79012f943d3b3af1f439022f05a1287a383cd3f8 (patch) | |
tree | 441da4ddfb3263f60ee24e012e0400624e9d03dd /bitbake/lib/bb/event.py | |
parent | 45f401abe59978b822e6198186ac5cd8c75d56ee (diff) | |
download | poky-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.py | 21 |
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 | |||
29 | import atexit | 29 | import atexit |
30 | import traceback | 30 | import traceback |
31 | import ast | 31 | import ast |
32 | import threading | ||
33 | |||
32 | import bb.utils | 34 | import bb.utils |
33 | import bb.compat | 35 | import bb.compat |
34 | import bb.exceptions | 36 | import 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 | ||
72 | if hasattr(__builtins__, '__setitem__'): | 76 | if hasattr(__builtins__, '__setitem__'): |
73 | builtins = __builtins__ | 77 | builtins = __builtins__ |
74 | else: | 78 | else: |
75 | builtins = __builtins__.__dict__ | 79 | builtins = __builtins__.__dict__ |
76 | 80 | ||
81 | def enable_threadlock(): | ||
82 | global _thread_lock_enabled | ||
83 | _thread_lock_enabled = True | ||
84 | |||
85 | def disable_threadlock(): | ||
86 | global _thread_lock_enabled | ||
87 | _thread_lock_enabled = False | ||
88 | |||
77 | def execute_handler(name, handler, event, d): | 89 | def 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 | ||
148 | def fire_ui_handlers(event, d): | 160 | def 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 | |||
172 | def fire(event, d): | 193 | def fire(event, d): |
173 | """Fire off an Event""" | 194 | """Fire off an Event""" |
174 | 195 | ||