Commit 954679b 1 parent ad9a39c commit 954679b Copy full SHA for 954679b
File tree 3 files changed +32
-4
lines changed
3 files changed +32
-4
lines changed Original file line number Diff line number Diff line change @@ -3331,10 +3331,10 @@ void DBImpl::InstallSuperVersion(DeletionState& deletion_state) {
3331
3331
DBImpl::SuperVersion* DBImpl::InstallSuperVersion (
3332
3332
SuperVersion* new_superversion) {
3333
3333
mutex_.AssertHeld ();
3334
+ new_superversion->db = this ;
3334
3335
new_superversion->Init (mem_, imm_.current (), versions_->current ());
3335
3336
SuperVersion* old_superversion = super_version_;
3336
3337
super_version_ = new_superversion;
3337
- super_version_->db = this ;
3338
3338
++super_version_number_;
3339
3339
super_version_->version_number = super_version_number_;
3340
3340
Original file line number Diff line number Diff line change 11
11
12
12
#include < cstdlib>
13
13
#include < stdio.h>
14
+ #include < assert.h>
14
15
#include < string.h>
15
16
#include " util/logging.h"
16
17
@@ -45,9 +46,25 @@ Mutex::Mutex(bool adaptive) {
45
46
46
47
Mutex::~Mutex () { PthreadCall (" destroy mutex" , pthread_mutex_destroy (&mu_)); }
47
48
48
- void Mutex::Lock () { PthreadCall (" lock" , pthread_mutex_lock (&mu_)); }
49
+ void Mutex::Lock () {
50
+ PthreadCall (" lock" , pthread_mutex_lock (&mu_));
51
+ #ifndef NDEBUG
52
+ locked_ = true ;
53
+ #endif
54
+ }
55
+
56
+ void Mutex::Unlock () {
57
+ #ifndef NDEBUG
58
+ locked_ = false ;
59
+ #endif
60
+ PthreadCall (" unlock" , pthread_mutex_unlock (&mu_));
61
+ }
49
62
50
- void Mutex::Unlock () { PthreadCall (" unlock" , pthread_mutex_unlock (&mu_)); }
63
+ void Mutex::AssertHeld () {
64
+ #ifndef NDEBUG
65
+ assert (locked_);
66
+ #endif
67
+ }
51
68
52
69
CondVar::CondVar (Mutex* mu)
53
70
: mu_(mu) {
@@ -57,7 +74,13 @@ CondVar::CondVar(Mutex* mu)
57
74
CondVar::~CondVar () { PthreadCall (" destroy cv" , pthread_cond_destroy (&cv_)); }
58
75
59
76
void CondVar::Wait () {
77
+ #ifndef NDEBUG
78
+ mu_->locked_ = false ;
79
+ #endif
60
80
PthreadCall (" wait" , pthread_cond_wait (&cv_, &mu_->mu_ ));
81
+ #ifndef NDEBUG
82
+ mu_->locked_ = true ;
83
+ #endif
61
84
}
62
85
63
86
void CondVar::Signal () {
Original file line number Diff line number Diff line change @@ -97,11 +97,16 @@ class Mutex {
97
97
98
98
void Lock ();
99
99
void Unlock ();
100
- void AssertHeld () { }
100
+ // this will assert if the mutex is not locked
101
+ // it does NOT verify that mutex is held by a calling thread
102
+ void AssertHeld ();
101
103
102
104
private:
103
105
friend class CondVar ;
104
106
pthread_mutex_t mu_;
107
+ #ifndef NDEBUG
108
+ bool locked_;
109
+ #endif
105
110
106
111
// No copying
107
112
Mutex (const Mutex&);
You can’t perform that action at this time.
0 commit comments