Skip to content

Commit

Permalink
Use shared_mutex and shared_lock
Browse files Browse the repository at this point in the history
Signed-off-by: Nghia Truong <[email protected]>
  • Loading branch information
ttnghia committed Jul 29, 2024
1 parent 79372f3 commit c02546a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions cpp/include/cudf/utilities/prefetch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <rmm/device_uvector.hpp>

#include <map>
#include <mutex>
#include <shared_mutex>
#include <string>
#include <string_view>

Expand Down Expand Up @@ -73,7 +73,7 @@ class prefetch_config {
private:
prefetch_config() = default; //< Private constructor to enforce singleton pattern
std::map<std::string, bool> 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
};

/**
Expand Down
9 changes: 5 additions & 4 deletions cpp/src/utilities/prefetch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::shared_mutex> 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<std::shared_mutex> lock(config_mtx);
config_values[key.data()] = value;
}

Expand Down

0 comments on commit c02546a

Please sign in to comment.