From: Joel Rosdahl Date: Fri, 19 Jun 2020 18:52:51 +0000 (+0200) Subject: Build InodeCache.cpp only when inode cache is supported X-Git-Tag: v4.0~373 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2354adc2d13807245aed330f6d1045286c7b3f22;p=thirdparty%2Fccache.git Build InodeCache.cpp only when inode cache is supported --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 09946819b..2a4ad08af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,10 @@ include(GNUInstallDirs) include(GenerateConfigurationFile) include(GenerateVersionFile) +if(HAVE_SYS_MMAN_H) + set(INODE_CACHE_SUPPORTED 1) +endif() + # # Third party # diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 61522b785..207513c1a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -11,7 +11,6 @@ set( Context.cpp Counters.cpp Decompressor.cpp - InodeCache.cpp Lockfile.cpp MiniTrace.cpp NullCompressor.cpp @@ -39,6 +38,10 @@ set( stats.cpp Version.cpp) +if(INODE_CACHE_SUPPORTED) + list(APPEND source_files InodeCache.cpp) +endif() + if(WIN32) list(APPEND source_files win32compat.cpp) endif() diff --git a/src/Context.hpp b/src/Context.hpp index 385daedee..9e8937376 100644 --- a/src/Context.hpp +++ b/src/Context.hpp @@ -24,12 +24,15 @@ #include "ArgsInfo.hpp" #include "Config.hpp" #include "File.hpp" -#include "InodeCache.hpp" #include "MiniTrace.hpp" #include "NonCopyable.hpp" #include "ccache.hpp" #include "hash.hpp" +#ifdef INODE_CACHE_SUPPORTED +# include "InodeCache.hpp" +#endif + #include "third_party/nonstd/optional.hpp" #include "third_party/nonstd/string_view.hpp" diff --git a/src/InodeCache.cpp b/src/InodeCache.cpp index e73c35b46..64cba5775 100644 --- a/src/InodeCache.cpp +++ b/src/InodeCache.cpp @@ -18,21 +18,19 @@ #include "InodeCache.hpp" -#ifdef INODE_CACHE_SUPPORTED - -# include "Config.hpp" -# include "Fd.hpp" -# include "Finalizer.hpp" -# include "Stat.hpp" -# include "Util.hpp" -# include "ccache.hpp" -# include "hash.hpp" -# include "logging.hpp" - -# include -# include -# include -# include +#include "Config.hpp" +#include "Fd.hpp" +#include "Finalizer.hpp" +#include "Stat.hpp" +#include "Util.hpp" +#include "ccache.hpp" +#include "hash.hpp" +#include "logging.hpp" + +#include +#include +#include +#include // The inode cache resides on a file that is mapped into shared memory by // running processes. It is implemented as a two level structure, where the top @@ -87,16 +85,16 @@ struct InodeCache::Key dev_t st_dev; ino_t st_ino; mode_t st_mode; -# ifdef HAVE_STRUCT_STAT_ST_MTIM +#ifdef HAVE_STRUCT_STAT_ST_MTIM timespec st_mtim; -# else +#else time_t st_mtim; -# endif -# ifdef HAVE_STRUCT_STAT_ST_CTIM +#endif +#ifdef HAVE_STRUCT_STAT_ST_CTIM timespec st_ctim; // Included for sanity checking. -# else +#else time_t st_ctim; // Included for sanity checking. -# endif +#endif off_t st_size; // Included for sanity checking. bool sloppy_time_macros; }; @@ -185,16 +183,16 @@ InodeCache::hash_inode(const char* path, ContentType type, Digest& digest) key.st_dev = stat.device(); key.st_ino = stat.inode(); key.st_mode = stat.mode(); -# ifdef HAVE_STRUCT_STAT_ST_MTIM +#ifdef HAVE_STRUCT_STAT_ST_MTIM key.st_mtim = stat.mtim(); -# else +#else key.st_mtim = stat.mtime(); -# endif -# ifdef HAVE_STRUCT_STAT_ST_CTIM +#endif +#ifdef HAVE_STRUCT_STAT_ST_CTIM key.st_ctim = stat.ctim(); -# else +#else key.st_ctim = stat.ctime(); -# endif +#endif key.st_size = stat.size(); digest = hash_buffer_once(&key, sizeof(Key)); @@ -206,7 +204,7 @@ InodeCache::acquire_bucket(uint32_t index) { Bucket* bucket = &m_sr->buckets[index]; int err = pthread_mutex_lock(&bucket->mt); -# ifdef PTHREAD_MUTEX_ROBUST +#ifdef PTHREAD_MUTEX_ROBUST if (err == EOWNERDEAD) { if (m_config.debug()) { ++m_sr->errors; @@ -221,16 +219,16 @@ InodeCache::acquire_bucket(uint32_t index) cc_log("Wiping bucket at index %u because of stale mutex", index); memset(bucket->entries, 0, sizeof(Bucket::entries)); } else { -# endif +#endif if (err) { cc_log("Failed to lock mutex at index %u: %s", index, strerror(err)); cc_log("Consider removing the inode cache file if problem persists"); ++m_sr->errors; return nullptr; } -# ifdef PTHREAD_MUTEX_ROBUST +#ifdef PTHREAD_MUTEX_ROBUST } -# endif +#endif return bucket; } @@ -291,9 +289,9 @@ InodeCache::create_new_file(const std::string& filename) pthread_mutexattr_t mattr; pthread_mutexattr_init(&mattr); pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED); -# ifdef PTHREAD_MUTEX_ROBUST +#ifdef PTHREAD_MUTEX_ROBUST pthread_mutexattr_setrobust(&mattr, PTHREAD_MUTEX_ROBUST); -# endif +#endif for (auto& bucket : sr->buckets) { pthread_mutex_init(&bucket.mt, &mattr); } @@ -487,5 +485,3 @@ InodeCache::get_errors() { return initialize() ? m_sr->errors.load() : -1; } - -#endif diff --git a/src/InodeCache.hpp b/src/InodeCache.hpp index a538940ed..1c0fdf06f 100644 --- a/src/InodeCache.hpp +++ b/src/InodeCache.hpp @@ -22,10 +22,8 @@ #include "config.h" -#ifdef INODE_CACHE_SUPPORTED - -# include -# include +#include +#include class Config; class Context; @@ -110,4 +108,3 @@ private: struct SharedRegion* m_sr = nullptr; bool m_failed = false; }; -#endif diff --git a/src/cleanup.cpp b/src/cleanup.cpp index e2a720a33..8423301d5 100644 --- a/src/cleanup.cpp +++ b/src/cleanup.cpp @@ -22,11 +22,14 @@ #include "CacheFile.hpp" #include "Config.hpp" #include "Context.hpp" -#include "InodeCache.hpp" #include "Util.hpp" #include "logging.hpp" #include "stats.hpp" +#ifdef INODE_CACHE_SUPPORTED +# include "InodeCache.hpp" +#endif + #include #include diff --git a/src/hashutil.cpp b/src/hashutil.cpp index 777c1e8ef..90bfe3ba5 100644 --- a/src/hashutil.cpp +++ b/src/hashutil.cpp @@ -21,7 +21,6 @@ #include "Args.hpp" #include "Config.hpp" #include "Context.hpp" -#include "InodeCache.hpp" #include "Stat.hpp" #include "ccache.hpp" #include "execute.hpp" @@ -29,6 +28,10 @@ #include "macroskip.hpp" #include "stats.hpp" +#ifdef INODE_CACHE_SUPPORTED +# include "InodeCache.hpp" +#endif + #include "third_party/xxhash.h" // With older GCC (libgcc), __builtin_cpu_supports("avx2) returns true if AVX2 diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index 7e3408165..6e6cfc4b1 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -1,5 +1,5 @@ -add_executable( - unittest +set( + source_files TestUtil.cpp catch2_tests.cpp main.cpp @@ -9,7 +9,6 @@ add_executable( test_Compression.cpp test_Config.cpp test_FormatNonstdStringView.cpp - test_InodeCache.cpp test_Lockfile.cpp test_NullCompression.cpp test_Stat.cpp @@ -21,6 +20,12 @@ add_executable( test_hashutil.cpp test_legacy_util.cpp) +if(INODE_CACHE_SUPPORTED) + list(APPEND source_files test_InodeCache.cpp) +endif() + +add_executable(unittest ${source_files}) + target_link_libraries( unittest PRIVATE standard_settings standard_warnings ccache_lib) diff --git a/unittest/test_InodeCache.cpp b/unittest/test_InodeCache.cpp index f2396116c..ae417055f 100644 --- a/unittest/test_InodeCache.cpp +++ b/unittest/test_InodeCache.cpp @@ -25,8 +25,6 @@ #include "third_party/catch.hpp" -#ifdef INODE_CACHE_SUPPORTED - using TestUtil::TestContext; namespace { @@ -203,5 +201,3 @@ TEST_CASE("Test content type") CHECK(digest == code_with_sloppy_time_macros_digest); CHECK(return_value == 3); } - -#endif