15 #ifndef SHAKA_EMBEDDED_UTIL_SHARED_LOCK_H_ 16 #define SHAKA_EMBEDDED_UTIL_SHARED_LOCK_H_ 21 # include <condition_variable> 66 maybe_try_lock(
false);
71 return maybe_try_lock(
true);
80 maybe_try_lock_shared(
false);
85 return maybe_try_lock_shared(
true);
92 bool maybe_try_lock(
bool only_try);
93 bool maybe_try_lock_shared(
bool only_try);
96 pthread_rwlock_t lock_;
99 std::condition_variable signal_;
100 uint32_t shared_count_ = 0;
101 bool is_exclusive_ =
false;
102 bool is_exclusive_waiting_ =
false;
111 template <
typename Mutex>
118 mutex_->lock_shared();
122 : mutex_(other.mutex_), owns_lock_(other.owns_lock_) {
123 other.mutex_ =
nullptr;
124 other.owns_lock_ =
false;
129 mutex_->unlock_shared();
139 operator bool()
const {
return owns_lock_; }
144 swap(mutex_, other.mutex_);
145 swap(owns_lock_, other.owns_lock_);
160 template <
typename Mutex>
168 #endif // SHAKA_EMBEDDED_UTIL_SHARED_LOCK_H_
mutex_type * mutex() const
shared_lock(mutex_type &mutex)
void swap(shared_lock &other)
shared_lock & operator=(shared_lock &&other)
void swap(shared_lock< Mutex > &a, shared_lock< Mutex > &b)
#define SHAKA_NON_COPYABLE_TYPE(Type)
SHAKA_NON_COPYABLE_OR_MOVABLE_TYPE(shared_mutex)
shared_lock(shared_lock &&other)