summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Rosdahl <joel@rosdahl.net>2023-01-04 15:17:11 +0100
committerJoel Rosdahl <joel@rosdahl.net>2023-01-04 15:17:11 +0100
commit162f778afe6af58b06132c41fb010309d2f935ec (patch)
tree2a26ebec24af384ec80de74f6e57fc457e5e4313
parent95e6375813f7970ff1dd80126d18a1bd3b2c3bd3 (diff)
downloadccache-162f778afe6af58b06132c41fb010309d2f935ec.tar.gz
chore: Clean up minor things after 95e6375813f7
-rw-r--r--cmake/GenerateConfigurationFile.cmake17
-rw-r--r--cmake/config.h.in6
-rw-r--r--src/InodeCache.cpp22
3 files changed, 10 insertions, 35 deletions
diff --git a/cmake/GenerateConfigurationFile.cmake b/cmake/GenerateConfigurationFile.cmake
index 858567b9..4fac7b03 100644
--- a/cmake/GenerateConfigurationFile.cmake
+++ b/cmake/GenerateConfigurationFile.cmake
@@ -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)
diff --git a/cmake/config.h.in b/cmake/config.h.in
index 1537119b..2778909e 100644
--- a/cmake/config.h.in
+++ b/cmake/config.h.in
@@ -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
@@ -181,9 +178,6 @@
// 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
diff --git a/src/InodeCache.cpp b/src/InodeCache.cpp
index b88ac23b..48afe21e 100644
--- a/src/InodeCache.cpp
+++ b/src/InodeCache.cpp
@@ -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;
}