From d2eb58abac2d25b188628e825eab75077eb7aac8 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Fri, 16 Oct 2009 18:18:30 +0000 Subject: Add support for a chain of stat caches in the FileManager, rather than only supporting a single stat cache. The immediate benefit of this change is that we can now generate a PCH/AST file when including another PCH file; in the future, the chain of stat caches will likely be useful with multiple levels of PCH files. llvm-svn: 84263 --- clang/lib/Basic/FileManager.cpp | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'clang/lib/Basic') diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index df86f9d0470..ee4309de937 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -149,6 +149,41 @@ FileManager::~FileManager() { delete &UniqueFiles; } +void FileManager::addStatCache(StatSysCallCache *statCache, bool AtBeginning) { + assert(statCache && "No stat cache provided?"); + if (AtBeginning || StatCache.get() == 0) { + statCache->setNextStatCache(StatCache.take()); + StatCache.reset(statCache); + return; + } + + StatSysCallCache *LastCache = StatCache.get(); + while (LastCache->getNextStatCache()) + LastCache = LastCache->getNextStatCache(); + + LastCache->setNextStatCache(statCache); +} + +void FileManager::removeStatCache(StatSysCallCache *statCache) { + if (!statCache) + return; + + if (StatCache.get() == statCache) { + // This is the first stat cache. + StatCache.reset(StatCache->takeNextStatCache()); + return; + } + + // Find the stat cache in the list. + StatSysCallCache *PrevCache = StatCache.get(); + while (PrevCache && PrevCache->getNextStatCache() != statCache) + PrevCache = PrevCache->getNextStatCache(); + if (PrevCache) + PrevCache->setNextStatCache(statCache->getNextStatCache()); + else + assert(false && "Stat cache not found for removal"); +} + /// getDirectory - Lookup, cache, and verify the specified directory. This /// returns null if the directory doesn't exist. /// @@ -290,8 +325,8 @@ void FileManager::PrintStats() const { } int MemorizeStatCalls::stat(const char *path, struct stat *buf) { - int result = ::stat(path, buf); - + int result = StatSysCallCache::stat(path, buf); + if (result != 0) { // Cache failed 'stat' results. struct stat empty; -- cgit v1.2.3