Skip to content

Commit 097d0d8

Browse files
ckennellycopybara-github
authored andcommitted
Add referenceful MutexLock with Condition overload.
PiperOrigin-RevId: 790787285 Change-Id: I571a6cf6e0f3940f7022d4d3ba89dc7fd2693db8
1 parent 8224c30 commit 097d0d8

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

absl/synchronization/mutex.h

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -612,12 +612,16 @@ class ABSL_SCOPED_LOCKABLE MutexLock {
612612
// Like above, but calls `mu->LockWhen(cond)` instead. That is, in addition to
613613
// the above, the condition given by `cond` is also guaranteed to hold when
614614
// this object is constructed.
615-
explicit MutexLock(Mutex* absl_nonnull mu, const Condition& cond)
615+
explicit MutexLock(Mutex& mu, const Condition& cond)
616616
ABSL_EXCLUSIVE_LOCK_FUNCTION(mu)
617-
: mu_(*mu) {
617+
: mu_(mu) {
618618
this->mu_.LockWhen(cond);
619619
}
620620

621+
explicit MutexLock(Mutex* absl_nonnull mu, const Condition& cond)
622+
ABSL_EXCLUSIVE_LOCK_FUNCTION(mu)
623+
: MutexLock(*mu, cond) {}
624+
621625
MutexLock(const MutexLock&) = delete; // NOLINT(runtime/mutex)
622626
MutexLock(MutexLock&&) = delete; // NOLINT(runtime/mutex)
623627
MutexLock& operator=(const MutexLock&) = delete;
@@ -1081,18 +1085,25 @@ class ABSL_SCOPED_LOCKABLE MutexLockMaybe {
10811085
// mutex before destruction. `Release()` may be called at most once.
10821086
class ABSL_SCOPED_LOCKABLE ReleasableMutexLock {
10831087
public:
1088+
explicit ReleasableMutexLock(Mutex& mu) ABSL_EXCLUSIVE_LOCK_FUNCTION(mu)
1089+
: mu_(&mu) {
1090+
this->mu_->Lock();
1091+
}
1092+
10841093
explicit ReleasableMutexLock(Mutex* absl_nonnull mu)
10851094
ABSL_EXCLUSIVE_LOCK_FUNCTION(mu)
1086-
: mu_(mu) {
1087-
this->mu_->lock();
1088-
}
1095+
: ReleasableMutexLock(*mu) {}
10891096

1090-
explicit ReleasableMutexLock(Mutex* absl_nonnull mu, const Condition& cond)
1097+
explicit ReleasableMutexLock(Mutex& mu, const Condition& cond)
10911098
ABSL_EXCLUSIVE_LOCK_FUNCTION(mu)
1092-
: mu_(mu) {
1099+
: mu_(&mu) {
10931100
this->mu_->LockWhen(cond);
10941101
}
10951102

1103+
explicit ReleasableMutexLock(Mutex* absl_nonnull mu, const Condition& cond)
1104+
ABSL_EXCLUSIVE_LOCK_FUNCTION(mu)
1105+
: ReleasableMutexLock(*mu, cond) {}
1106+
10961107
~ReleasableMutexLock() ABSL_UNLOCK_FUNCTION() {
10971108
if (this->mu_ != nullptr) {
10981109
this->mu_->unlock();

0 commit comments

Comments
 (0)