]> git.proxmox.com Git - ceph.git/blame - ceph/src/common/shared_mutex_debug.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / common / shared_mutex_debug.h
CommitLineData
11fdf7f2
TL
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3
4#pragma once
5
6#include <pthread.h>
7#include <atomic>
8
9#include "common/mutex_debug.h"
10
11namespace ceph {
12
13class shared_mutex_debug :
14 public ceph::mutex_debug_detail::mutex_debugging_base
15{
16 pthread_rwlock_t rwlock;
17 const bool track;
11fdf7f2
TL
18 std::atomic<unsigned> nrlock{0};
19
20public:
9f95a23c 21 shared_mutex_debug(std::string group,
11fdf7f2
TL
22 bool track_lock=true,
23 bool enable_lock_dep=true,
24 bool prioritize_write=false);
25 // exclusive locking
26 void lock();
27 bool try_lock();
28 void unlock();
9f95a23c
TL
29 bool is_wlocked() const {
30 return nlock > 0;
31 }
11fdf7f2
TL
32 // shared locking
33 void lock_shared();
34 bool try_lock_shared();
35 void unlock_shared();
9f95a23c
TL
36 bool is_rlocked() const {
37 return nrlock > 0;
38 }
39 // either of them
40 bool is_locked() const {
41 return nlock > 0 || nrlock > 0;
42 }
11fdf7f2
TL
43private:
44 // exclusive locking
45 void _pre_unlock();
46 void _post_lock();
47 // shared locking
48 void _pre_unlock_shared();
49 void _post_lock_shared();
50};
51
52} // namespace ceph