blob: 57d95b0c1d55fb5f62197f7ebc2ad0a9cee6ad57 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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
|