Skip to content

Commit

Permalink
Fix: shared_lock_gt for C++11
Browse files Browse the repository at this point in the history
  • Loading branch information
ashvardanian committed Aug 22, 2023
1 parent 4570ee3 commit f988fc3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/usearch/index_dense.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ class index_dense_gt {
mutable std::mutex available_threads_mutex_;

using shared_mutex_t = unfair_shared_mutex_t;
using shared_lock_t = std::shared_lock<shared_mutex_t>;
using shared_lock_t = shared_lock_gt<shared_mutex_t>;
using unique_lock_t = std::unique_lock<shared_mutex_t>;

struct key_and_slot_t {
Expand Down
8 changes: 8 additions & 0 deletions include/usearch/index_plugins.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,14 @@ class unfair_shared_mutex_t {
}
};

template <typename mutex_at = unfair_shared_mutex_t> class shared_lock_gt {
mutex_at& mutex_;

public:
inline explicit shared_lock_gt(mutex_at& m) noexcept : mutex_(m) { mutex_.lock_shared(); }
inline ~shared_lock_gt() noexcept { mutex_.unlock_shared(); }
};

/**
* @brief Utility class used to cast arrays of one scalar type to another,
* avoiding unnecessary conversions.
Expand Down

0 comments on commit f988fc3

Please sign in to comment.