From c02546a1418cf011cde988cc456cc95bff5ce9c6 Mon Sep 17 00:00:00 2001 From: Nghia Truong Date: Mon, 29 Jul 2024 11:23:24 -0700 Subject: [PATCH] Use `shared_mutex` and `shared_lock` Signed-off-by: Nghia Truong --- cpp/include/cudf/utilities/prefetch.hpp | 4 ++-- cpp/src/utilities/prefetch.cpp | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/cpp/include/cudf/utilities/prefetch.hpp b/cpp/include/cudf/utilities/prefetch.hpp index d794ef7d015..1bf838bc3c2 100644 --- a/cpp/include/cudf/utilities/prefetch.hpp +++ b/cpp/include/cudf/utilities/prefetch.hpp @@ -21,7 +21,7 @@ #include #include -#include +#include #include #include @@ -73,7 +73,7 @@ class prefetch_config { private: prefetch_config() = default; //< Private constructor to enforce singleton pattern std::map config_values; //< Map of configuration keys to values - std::mutex config_mtx; //< Mutex for thread-safe config access + std::shared_mutex config_mtx; //< Mutex for thread-safe config access }; /** diff --git a/cpp/src/utilities/prefetch.cpp b/cpp/src/utilities/prefetch.cpp index bf803e788a1..173ac886232 100644 --- a/cpp/src/utilities/prefetch.cpp +++ b/cpp/src/utilities/prefetch.cpp @@ -34,15 +34,16 @@ prefetch_config& prefetch_config::instance() bool prefetch_config::get(std::string_view key) const { - std::scoped_lock lock(config_mtx); - // Default to not prefetching - if (config_values.find(key.data()) == config_values.end()) { return false; } + std::shared_lock lock(config_mtx); + if (config_values.find(key.data()) == config_values.end()) { + return false; // default to not prefetching + } return config_values.at(key.data()); } void prefetch_config::set(std::string_view key, bool value) { - std::scoped_lock lock(config_mtx); + std::lock_guard lock(config_mtx); config_values[key.data()] = value; }