mirror of
https://gitlab.com/ita1024/waf.git
synced 2024-11-25 11:19:52 +01:00
gccdeps: Refactor cache lock
Rework how gccdeps' 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.
Ported from 8b5a2a2086
This commit is contained in:
parent
bf97987991
commit
22b72e167f
@ -54,14 +54,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):
|
||||
|
Loading…
Reference in New Issue
Block a user