]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
chore: Clean up minor things after 95e6375813f7
authorJoel Rosdahl <joel@rosdahl.net>
Wed, 4 Jan 2023 14:17:11 +0000 (15:17 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Wed, 4 Jan 2023 14:17:11 +0000 (15:17 +0100)
cmake/GenerateConfigurationFile.cmake
cmake/config.h.in
src/InodeCache.cpp

index 858567b94a6e8dfac90db3828588c810ba0f8c01..4fac7b032ccd72671a5d38496637a39dd39dabdb 100644 (file)
@@ -43,22 +43,6 @@ foreach(func IN ITEMS ${functions})
   check_function_exists(${func} ${func_var})
 endforeach()
 
-include(CheckCXXSourceCompiles)
-set(CMAKE_REQUIRED_FLAGS -pthread)
-check_cxx_source_compiles(
-  [=[
-    #include <pthread.h>
-    int main()
-    {
-      pthread_mutexattr_t attr;
-      (void)pthread_mutexattr_setrobust(&attr, PTHREAD_MUTEX_ROBUST);
-      return 0;
-    }
-  ]=]
-  HAVE_PTHREAD_MUTEX_ROBUST)
-check_function_exists(pthread_mutexattr_setpshared HAVE_PTHREAD_MUTEXATTR_SETPSHARED)
-set(CMAKE_REQUIRED_FLAGS)
-
 include(CheckStructHasMember)
 check_struct_has_member("struct stat" st_atim sys/stat.h
                         HAVE_STRUCT_STAT_ST_ATIM LANGUAGE CXX)
@@ -103,7 +87,6 @@ endif()
 set(MTR_ENABLED "${ENABLE_TRACING}")
 
 if(HAVE_SYS_MMAN_H
-   AND HAVE_PTHREAD_MUTEXATTR_SETPSHARED
    AND (HAVE_STRUCT_STAT_ST_MTIM OR HAVE_STRUCT_STAT_ST_MTIMESPEC)
    AND (HAVE_LINUX_FS_H OR HAVE_STRUCT_STATFS_F_FSTYPENAME))
   set(INODE_CACHE_SUPPORTED 1)
index 1537119b84e6514a9f391bb8089ccc398e4ecba8..2778909eab08167d505b4cda708bb177af0f9531 100644 (file)
@@ -91,9 +91,6 @@
 // Define if you have the "posix_fallocate.
 #cmakedefine HAVE_POSIX_FALLOCATE
 
-// Define if you have the "pthread_mutexattr_setpshared" function.
-#cmakedefine HAVE_PTHREAD_MUTEXATTR_SETPSHARED
-
 // Define if you have the <pwd.h> header file.
 #cmakedefine HAVE_PWD_H
 
 // Define if you have the "utimes" function.
 #cmakedefine HAVE_UTIMES
 
-// Define if you have the "PTHREAD_MUTEX_ROBUST" constant.
-#cmakedefine HAVE_PTHREAD_MUTEX_ROBUST
-
 #if defined(__ibmxl__) && defined(__clang__) // Compiler xlclang
 #  undef HAVE_VARARGS_H // varargs.h would hide macros of stdarg.h
 #  undef HAVE_STRUCT_STAT_ST_CTIM
index b88ac23b22fda87e9cc5737430f56e9c17159689..48afe21e637b760fc75e2ca7dbc601d3baaa3d48 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020-2022 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2023 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -153,13 +153,13 @@ spin_lock(std::atomic<pid_t>& owner_pid, const pid_t self_pid)
   pid_t lock_pid = 0;
   bool reset_timer = false;
   util::TimePoint lock_time;
-  for (;;) {
+  while (true) {
     for (int i = 0; i < 10000; ++i) {
       lock_pid = owner_pid.load(std::memory_order_relaxed);
       if (lock_pid == 0
           && owner_pid.compare_exchange_weak(
             lock_pid, self_pid, std::memory_order_acquire)) {
-        return false;
+        return true;
       }
 
       if (prev_pid != lock_pid) {
@@ -174,10 +174,8 @@ spin_lock(std::atomic<pid_t>& owner_pid, const pid_t self_pid)
     if (reset_timer) {
       lock_time = util::TimePoint::now();
       reset_timer = false;
-    } else {
-      if (util::TimePoint::now() - lock_time > MAX_LOCK_DURATION) {
-        return true;
-      }
+    } else if (util::TimePoint::now() - lock_time > MAX_LOCK_DURATION) {
+      return false;
     }
   }
 }
@@ -306,9 +304,9 @@ InodeCache::with_bucket(const Digest& key_digest,
   Util::big_endian_to_int(key_digest.bytes(), hash);
   const uint32_t index = hash % k_num_buckets;
   Bucket* bucket = &m_sr->buckets[index];
-  bool broken_lock = spin_lock(bucket->owner_pid, m_self_pid);
-  while (broken_lock) {
-    LOG("Wiping inodes cache because of stale mutex at index {}", index);
+  bool acquired_lock = spin_lock(bucket->owner_pid, m_self_pid);
+  while (!acquired_lock) {
+    LOG("Dropping inode cache file because of stale mutex at index {}", index);
     if (!drop() || !initialize()) {
       return false;
     }
@@ -316,7 +314,7 @@ InodeCache::with_bucket(const Digest& key_digest,
       ++m_sr->errors;
     }
     bucket = &m_sr->buckets[index];
-    broken_lock = spin_lock(bucket->owner_pid, m_self_pid);
+    acquired_lock = spin_lock(bucket->owner_pid, m_self_pid);
   }
   try {
     bucket_handler(bucket);
@@ -341,7 +339,7 @@ InodeCache::create_new_file(const std::string& filename)
     return false;
   }
   int err = Util::fallocate(*tmp_file.fd, sizeof(SharedRegion));
-  if (err) {
+  if (err != 0) {
     LOG("Failed to allocate file space for inode cache: {}", strerror(err));
     return false;
   }