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>
This commit is contained in:
parent
45f401abe5
commit
79012f943d
|
@ -29,6 +29,8 @@ import logging
|
||||||
import atexit
|
import atexit
|
||||||
import traceback
|
import traceback
|
||||||
import ast
|
import ast
|
||||||
|
import threading
|
||||||
|
|
||||||
import bb.utils
|
import bb.utils
|
||||||
import bb.compat
|
import bb.compat
|
||||||
import bb.exceptions
|
import bb.exceptions
|
||||||
|
@ -68,12 +70,22 @@ _event_handler_map = {}
|
||||||
_catchall_handlers = {}
|
_catchall_handlers = {}
|
||||||
_eventfilter = None
|
_eventfilter = None
|
||||||
_uiready = False
|
_uiready = False
|
||||||
|
_thread_lock = threading.Lock()
|
||||||
|
_thread_lock_enabled = False
|
||||||
|
|
||||||
if hasattr(__builtins__, '__setitem__'):
|
if hasattr(__builtins__, '__setitem__'):
|
||||||
builtins = __builtins__
|
builtins = __builtins__
|
||||||
else:
|
else:
|
||||||
builtins = __builtins__.__dict__
|
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):
|
def execute_handler(name, handler, event, d):
|
||||||
event.data = d
|
event.data = d
|
||||||
addedd = False
|
addedd = False
|
||||||
|
@ -146,11 +158,17 @@ def print_ui_queue():
|
||||||
logger.handle(event)
|
logger.handle(event)
|
||||||
|
|
||||||
def fire_ui_handlers(event, d):
|
def fire_ui_handlers(event, d):
|
||||||
|
global _thread_lock
|
||||||
|
global _thread_lock_enabled
|
||||||
|
|
||||||
if not _uiready:
|
if not _uiready:
|
||||||
# No UI handlers registered yet, queue up the messages
|
# No UI handlers registered yet, queue up the messages
|
||||||
ui_queue.append(event)
|
ui_queue.append(event)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if _thread_lock_enabled:
|
||||||
|
_thread_lock.acquire()
|
||||||
|
|
||||||
errors = []
|
errors = []
|
||||||
for h in _ui_handlers:
|
for h in _ui_handlers:
|
||||||
#print "Sending event %s" % event
|
#print "Sending event %s" % event
|
||||||
|
@ -169,6 +187,9 @@ def fire_ui_handlers(event, d):
|
||||||
for h in errors:
|
for h in errors:
|
||||||
del _ui_handlers[h]
|
del _ui_handlers[h]
|
||||||
|
|
||||||
|
if _thread_lock_enabled:
|
||||||
|
_thread_lock.release()
|
||||||
|
|
||||||
def fire(event, d):
|
def fire(event, d):
|
||||||
"""Fire off an Event"""
|
"""Fire off an Event"""
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue