Skip to content
This repository was archived by the owner on Feb 4, 2020. It is now read-only.

Commit f8db2a0

Browse files
committed
Move cache lock inside clearCache, cleanCache and printStatistics
Hide locking inside these functions to have more fine-grained control. Since writing to the statistics file is now atomic, locking is not needed.
1 parent 9b82e34 commit f8db2a0

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

clcache.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,17 +1406,17 @@ def printStatistics(cache):
14061406

14071407

14081408
def resetStatistics(cache):
1409-
with cache.statistics as stats:
1409+
with cache.statistics.lock, cache.statistics as stats:
14101410
stats.resetCounters()
14111411

14121412

14131413
def cleanCache(cache):
1414-
with cache.statistics as stats, cache.configuration as cfg:
1414+
with cache.lock, cache.statistics as stats, cache.configuration as cfg:
14151415
cache.clean(stats, cfg.maximumCacheSize())
14161416

14171417

14181418
def clearCache(cache):
1419-
with cache.statistics as stats:
1419+
with cache.lock, cache.statistics as stats:
14201420
cache.clean(stats, 0)
14211421

14221422

@@ -1522,25 +1522,21 @@ def main():
15221522
cache = Cache()
15231523

15241524
if len(sys.argv) == 2 and sys.argv[1] == "-s":
1525-
with cache.lock:
1526-
printStatistics(cache)
1525+
printStatistics(cache)
15271526
return 0
15281527

15291528
if len(sys.argv) == 2 and sys.argv[1] == "-c":
1530-
with cache.lock:
1531-
cleanCache(cache)
1529+
cleanCache(cache)
15321530
print('Cache cleaned')
15331531
return 0
15341532

15351533
if len(sys.argv) == 2 and sys.argv[1] == "-C":
1536-
with cache.lock:
1537-
clearCache(cache)
1534+
clearCache(cache)
15381535
print('Cache cleared')
15391536
return 0
15401537

15411538
if len(sys.argv) == 2 and sys.argv[1] == "-z":
1542-
with cache.lock:
1543-
resetStatistics(cache)
1539+
resetStatistics(cache)
15441540
print('Statistics reset')
15451541
return 0
15461542

@@ -1652,8 +1648,7 @@ def scheduleJobs(cache, compiler, cmdLine, environment, sourceFiles, objectFiles
16521648
break
16531649

16541650
if cleanupRequired:
1655-
with cache.lock:
1656-
cleanCache(cache)
1651+
cleanCache(cache)
16571652

16581653
return exitCode
16591654

0 commit comments

Comments
 (0)