diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/common/shared_mutex_debug.h | |
parent | Initial commit. (diff) | |
download | ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/common/shared_mutex_debug.h')
-rw-r--r-- | src/common/shared_mutex_debug.h | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/common/shared_mutex_debug.h b/src/common/shared_mutex_debug.h new file mode 100644 index 00000000..57d95b0c --- /dev/null +++ b/src/common/shared_mutex_debug.h @@ -0,0 +1,57 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#pragma once + +#include <pthread.h> +#include <atomic> + +#include "common/mutex_debug.h" + +namespace ceph { + +class shared_mutex_debug : + public ceph::mutex_debug_detail::mutex_debugging_base +{ + pthread_rwlock_t rwlock; + const bool track; + const bool lockdep; + std::atomic<unsigned> nrlock{0}; + +public: + // Mutex concept is DefaultConstructible + shared_mutex_debug() + : shared_mutex_debug{std::string{}} + {} + shared_mutex_debug(const std::string& n, + bool track_lock=true, + bool enable_lock_dep=true, + bool prioritize_write=false); + // exclusive locking + void lock(); + bool try_lock(); + void unlock(); + bool is_wlocked() const { + return nlock > 0; + } + // shared locking + void lock_shared(); + bool try_lock_shared(); + void unlock_shared(); + bool is_rlocked() const { + return nrlock > 0; + } + // either of them + bool is_locked() const { + return nlock > 0 || nrlock > 0; + } +private: + // exclusive locking + void _pre_unlock(); + void _post_lock(); + // shared locking + void _pre_unlock_shared(); + void _post_lock_shared(); +}; + +} // namespace ceph |