From 8b5a2a2086dd67070ff26b6c65019bcbbea18836 Mon Sep 17 00:00:00 2001 From: Michael Vincent Date: Thu, 25 Apr 2019 16:28:19 -0500 Subject: [PATCH] msvcdeps: refactor cache lock Rework how msvcdeps' cached_nodes lock is used so acquiring the lock is only necessary on a cache miss. Also use a "with" context manager to simplify management of the lock lifecycle. --- waflib/extras/msvcdeps.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/waflib/extras/msvcdeps.py b/waflib/extras/msvcdeps.py index b9ec25f4..2c5577d3 100644 --- a/waflib/extras/msvcdeps.py +++ b/waflib/extras/msvcdeps.py @@ -64,14 +64,17 @@ def path_to_node(base_node, path, cached_nodes): else: # Not hashable, assume it is a list and join into a string node_lookup_key = (base_node, os.path.sep.join(path)) + try: - lock.acquire() node = cached_nodes[node_lookup_key] except KeyError: - node = base_node.find_resource(path) - cached_nodes[node_lookup_key] = node - finally: - lock.release() + # retry with lock on cache miss + with lock: + try: + node = cached_nodes[node_lookup_key] + except KeyError: + node = cached_nodes[node_lookup_key] = base_node.find_resource(path) + return node def post_run(self):