mirror of
https://gitlab.com/ita1024/waf.git
synced 2024-11-22 01:46:15 +01:00
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.
This commit is contained in:
parent
e874342103
commit
8b5a2a2086
@ -64,14 +64,17 @@ def path_to_node(base_node, path, cached_nodes):
|
|||||||
else:
|
else:
|
||||||
# Not hashable, assume it is a list and join into a string
|
# Not hashable, assume it is a list and join into a string
|
||||||
node_lookup_key = (base_node, os.path.sep.join(path))
|
node_lookup_key = (base_node, os.path.sep.join(path))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
lock.acquire()
|
|
||||||
node = cached_nodes[node_lookup_key]
|
node = cached_nodes[node_lookup_key]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
node = base_node.find_resource(path)
|
# retry with lock on cache miss
|
||||||
cached_nodes[node_lookup_key] = node
|
with lock:
|
||||||
finally:
|
try:
|
||||||
lock.release()
|
node = cached_nodes[node_lookup_key]
|
||||||
|
except KeyError:
|
||||||
|
node = cached_nodes[node_lookup_key] = base_node.find_resource(path)
|
||||||
|
|
||||||
return node
|
return node
|
||||||
|
|
||||||
def post_run(self):
|
def post_run(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user