diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-12-30 21:55:59 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-12-31 17:05:17 +0000 |
commit | 3cc9aed5a59d7b72b98ef40727102c98b031f911 (patch) | |
tree | d206bb855d2a794d5034d8e1ed45e98cdc8cf7c6 /bitbake/lib/bb/server/process.py | |
parent | 6a6a5c01f768f2af581f1f764a3a1c40864459e7 (diff) | |
download | poky-3cc9aed5a59d7b72b98ef40727102c98b031f911.tar.gz |
bitbake: server/process: Add locking around idle functions accesses
In preparation for adding splitting bitbakes work into two threads,
add locking around the idle functions list accesses.
(Bitbake rev: a9c63ce8932898b595fb7776cf5467d3c0afe4f7)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/server/process.py')
-rw-r--r-- | bitbake/lib/bb/server/process.py | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/bitbake/lib/bb/server/process.py b/bitbake/lib/bb/server/process.py index 5acc105e08..2aee9ef051 100644 --- a/bitbake/lib/bb/server/process.py +++ b/bitbake/lib/bb/server/process.py | |||
@@ -93,6 +93,7 @@ class ProcessServer(): | |||
93 | self.xmlrpc = False | 93 | self.xmlrpc = False |
94 | 94 | ||
95 | self._idlefuns = {} | 95 | self._idlefuns = {} |
96 | self._idlefuncsLock = threading.Lock() | ||
96 | 97 | ||
97 | self.bitbake_lock = lock | 98 | self.bitbake_lock = lock |
98 | self.bitbake_lock_name = lockname | 99 | self.bitbake_lock_name = lockname |
@@ -109,7 +110,8 @@ class ProcessServer(): | |||
109 | def register_idle_function(self, function, data): | 110 | def register_idle_function(self, function, data): |
110 | """Register a function to be called while the server is idle""" | 111 | """Register a function to be called while the server is idle""" |
111 | assert hasattr(function, '__call__') | 112 | assert hasattr(function, '__call__') |
112 | self._idlefuns[function] = data | 113 | with self._idlefuncsLock: |
114 | self._idlefuns[function] = data | ||
113 | serverlog("Registering idle function %s" % str(function)) | 115 | serverlog("Registering idle function %s" % str(function)) |
114 | 116 | ||
115 | def run(self): | 117 | def run(self): |
@@ -358,21 +360,28 @@ class ProcessServer(): | |||
358 | serverlog("".join(msg)) | 360 | serverlog("".join(msg)) |
359 | 361 | ||
360 | def idle_commands(self, delay, fds=None): | 362 | def idle_commands(self, delay, fds=None): |
363 | def remove_idle_func(function): | ||
364 | with self._idlefuncsLock: | ||
365 | del self._idlefuns[function] | ||
366 | |||
361 | nextsleep = delay | 367 | nextsleep = delay |
362 | if not fds: | 368 | if not fds: |
363 | fds = [] | 369 | fds = [] |
364 | 370 | ||
365 | for function, data in list(self._idlefuns.items()): | 371 | with self._idlefuncsLock: |
372 | items = list(self._idlefuns.items()) | ||
373 | |||
374 | for function, data in items: | ||
366 | try: | 375 | try: |
367 | retval = function(self, data, False) | 376 | retval = function(self, data, False) |
368 | if isinstance(retval, idleFinish): | 377 | if isinstance(retval, idleFinish): |
369 | serverlog("Removing idle function %s at idleFinish" % str(function)) | 378 | serverlog("Removing idle function %s at idleFinish" % str(function)) |
370 | del self._idlefuns[function] | 379 | remove_idle_func(function) |
371 | self.cooker.command.finishAsyncCommand(retval.msg) | 380 | self.cooker.command.finishAsyncCommand(retval.msg) |
372 | nextsleep = None | 381 | nextsleep = None |
373 | elif retval is False: | 382 | elif retval is False: |
374 | serverlog("Removing idle function %s" % str(function)) | 383 | serverlog("Removing idle function %s" % str(function)) |
375 | del self._idlefuns[function] | 384 | remove_idle_func(function) |
376 | nextsleep = None | 385 | nextsleep = None |
377 | elif retval is True: | 386 | elif retval is True: |
378 | nextsleep = None | 387 | nextsleep = None |
@@ -388,7 +397,7 @@ class ProcessServer(): | |||
388 | except Exception as exc: | 397 | except Exception as exc: |
389 | if not isinstance(exc, bb.BBHandledException): | 398 | if not isinstance(exc, bb.BBHandledException): |
390 | logger.exception('Running idle function') | 399 | logger.exception('Running idle function') |
391 | del self._idlefuns[function] | 400 | remove_idle_func(function) |
392 | serverlog("Exception %s broke the idle_thread, exiting" % traceback.format_exc()) | 401 | serverlog("Exception %s broke the idle_thread, exiting" % traceback.format_exc()) |
393 | self.quit = True | 402 | self.quit = True |
394 | 403 | ||