From 3eccc3a6339383b172a912d087d5f901c334ef02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Thu, 14 Jan 2016 03:32:18 +0100 Subject: [PATCH] qmemman: use try/finally to really release the lock Currently not needed in practice, but a preparation for the next commit(s). QubesOS/qubes-issues#1389 --- qmemman/qmemman_server.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/qmemman/qmemman_server.py b/qmemman/qmemman_server.py index 6e6fa94c..31aeb587 100755 --- a/qmemman/qmemman_server.py +++ b/qmemman/qmemman_server.py @@ -93,22 +93,22 @@ class XS_Watcher: self.log.debug('acquiring global_lock') global_lock.acquire() self.log.debug('global_lock acquired') + try: + for i in only_in_first_list(curr, self.watch_token_dict.keys()): + #new domain has been created + watch = WatchType(XS_Watcher.meminfo_changed, i) + self.watch_token_dict[i] = watch + self.handle.watch(get_domain_meminfo_key(i), watch) + system_state.add_domain(i) - for i in only_in_first_list(curr, self.watch_token_dict.keys()): -#new domain has been created - watch = WatchType(XS_Watcher.meminfo_changed, i) - self.watch_token_dict[i] = watch - self.handle.watch(get_domain_meminfo_key(i), watch) - system_state.add_domain(i) - - for i in only_in_first_list(self.watch_token_dict.keys(), curr): -#domain destroyed - self.handle.unwatch(get_domain_meminfo_key(i), self.watch_token_dict[i]) - self.watch_token_dict.pop(i) - system_state.del_domain(i) - - global_lock.release() - self.log.debug('global_lock released') + for i in only_in_first_list(self.watch_token_dict.keys(), curr): + #domain destroyed + self.handle.unwatch(get_domain_meminfo_key(i), self.watch_token_dict[i]) + self.watch_token_dict.pop(i) + system_state.del_domain(i) + finally: + global_lock.release() + self.log.debug('global_lock released') system_state.do_balance()