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

Commit b880939

Browse files
siufrerich
authored andcommitted
Revert reading manifests and statistics without acquiring the lock (#292)
Unfortunately windows does not allow to replace a file that is opened for reading by another process/thread. Reads and writes need to be serialized by using the locks. This reverts the locking of manifests and statistics to the state before pull request #286.
1 parent c958c58 commit b880939

1 file changed

Lines changed: 33 additions & 34 deletions

File tree

clcache.py

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,7 +1379,7 @@ def printStatistics(cache):
13791379
called w/ multiple sources : {}
13801380
called w/ PCH : {}""".strip()
13811381

1382-
with cache.statistics as stats, cache.configuration as cfg:
1382+
with cache.statistics.lock, cache.statistics as stats, cache.configuration as cfg:
13831383
print(template.format(
13841384
str(cache),
13851385
stats.currentCacheSize(),
@@ -1665,35 +1665,34 @@ def processSingleSource(compiler, cmdLine, sourceFile, objectFile, environment):
16651665
def processDirect(cache, objectFile, compiler, cmdLine, sourceFile):
16661666
manifestHash = ManifestRepository.getManifestHash(compiler, cmdLine, sourceFile)
16671667
manifestHit = None
1668-
manifest = cache.getManifest(manifestHash)
1669-
if manifest:
1670-
for entryIndex, entry in enumerate(manifest.entries()):
1671-
# NOTE: command line options already included in hash for manifest name
1672-
try:
1673-
includesContentHash = ManifestRepository.getIncludesContentHashForFiles(
1674-
[expandBasedirPlaceholder(path) for path in entry.includeFiles])
1675-
1676-
if entry.includesContentHash == includesContentHash:
1677-
cachekey = entry.objectHash
1678-
assert cachekey is not None
1679-
if entryIndex > 0:
1680-
# Move manifest entry to the top of the entries in the manifest
1681-
with cache.manifestLockFor(manifestHash):
1682-
manifest = cache.getManifest(manifestHash) or Manifest()
1668+
with cache.manifestLockFor(manifestHash):
1669+
manifest = cache.getManifest(manifestHash)
1670+
if manifest:
1671+
for entryIndex, entry in enumerate(manifest.entries()):
1672+
# NOTE: command line options already included in hash for manifest name
1673+
try:
1674+
includesContentHash = ManifestRepository.getIncludesContentHashForFiles(
1675+
[expandBasedirPlaceholder(path) for path in entry.includeFiles])
1676+
1677+
if entry.includesContentHash == includesContentHash:
1678+
cachekey = entry.objectHash
1679+
assert cachekey is not None
1680+
if entryIndex > 0:
1681+
# Move manifest entry to the top of the entries in the manifest
16831682
manifest.touchEntry(cachekey)
16841683
cache.setManifest(manifestHash, manifest)
16851684

1686-
manifestHit = True
1687-
with cache.lockFor(cachekey):
1688-
if cache.hasEntry(cachekey):
1689-
return processCacheHit(cache, objectFile, cachekey)
1685+
manifestHit = True
1686+
with cache.lockFor(cachekey):
1687+
if cache.hasEntry(cachekey):
1688+
return processCacheHit(cache, objectFile, cachekey)
16901689

1691-
except IncludeNotFoundException:
1692-
pass
1690+
except IncludeNotFoundException:
1691+
pass
16931692

1694-
unusableManifestMissReason = Statistics.registerHeaderChangedMiss
1695-
else:
1696-
unusableManifestMissReason = Statistics.registerSourceChangedMiss
1693+
unusableManifestMissReason = Statistics.registerHeaderChangedMiss
1694+
else:
1695+
unusableManifestMissReason = Statistics.registerSourceChangedMiss
16971696

16981697
if manifestHit is None:
16991698
stripIncludes = False
@@ -1706,21 +1705,21 @@ def processDirect(cache, objectFile, compiler, cmdLine, sourceFile):
17061705
includePaths, compilerOutput = parseIncludesSet(compilerResult[1], sourceFile, stripIncludes)
17071706
compilerResult = (compilerResult[0], compilerOutput, compilerResult[2])
17081707

1709-
if manifestHit is not None:
1710-
return ensureArtifactsExist(cache, cachekey, unusableManifestMissReason,
1711-
objectFile, compilerResult)
1708+
with cache.manifestLockFor(manifestHash):
1709+
if manifestHit is not None:
1710+
return ensureArtifactsExist(cache, cachekey, unusableManifestMissReason,
1711+
objectFile, compilerResult)
17121712

1713-
entry = createManifestEntry(manifestHash, includePaths)
1714-
cachekey = entry.objectHash
1713+
entry = createManifestEntry(manifestHash, includePaths)
1714+
cachekey = entry.objectHash
17151715

1716-
def addManifest():
1717-
with cache.manifestLockFor(manifestHash):
1716+
def addManifest():
17181717
manifest = cache.getManifest(manifestHash) or Manifest()
17191718
manifest.addEntry(entry)
17201719
cache.setManifest(manifestHash, manifest)
17211720

1722-
return ensureArtifactsExist(cache, cachekey, unusableManifestMissReason,
1723-
objectFile, compilerResult, addManifest)
1721+
return ensureArtifactsExist(cache, cachekey, unusableManifestMissReason,
1722+
objectFile, compilerResult, addManifest)
17241723

17251724

17261725
def processNoDirect(cache, objectFile, compiler, cmdLine, environment):

0 commit comments

Comments
 (0)