Skip to content

Commit d473c92

Browse files
ckennellycopybara-github
authored andcommitted
Inline internal usages of Mutex::Lock, etc. in favor of lock.
PiperOrigin-RevId: 789459507 Change-Id: I573dec1c33b047388509cfea129342ea7bdfe494
1 parent 0f1abc9 commit d473c92

File tree

9 files changed

+173
-170
lines changed

9 files changed

+173
-170
lines changed

absl/flags/internal/flag.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ bool ShouldValidateFlagValue(FlagFastTypeId flag_type_id) {
7373
// need to acquire these locks themselves.
7474
class MutexRelock {
7575
public:
76-
explicit MutexRelock(absl::Mutex& mu) : mu_(mu) { mu_.Unlock(); }
77-
~MutexRelock() { mu_.Lock(); }
76+
explicit MutexRelock(absl::Mutex& mu) : mu_(mu) { mu_.unlock(); }
77+
~MutexRelock() { mu_.lock(); }
7878

7979
MutexRelock(const MutexRelock&) = delete;
8080
MutexRelock& operator=(const MutexRelock&) = delete;

absl/flags/reflection.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@ class FlagRegistry {
5353
// Store a flag in this registry. Takes ownership of *flag.
5454
void RegisterFlag(CommandLineFlag& flag, const char* filename);
5555

56-
void Lock() ABSL_EXCLUSIVE_LOCK_FUNCTION(lock_) { lock_.Lock(); }
57-
void Unlock() ABSL_UNLOCK_FUNCTION(lock_) { lock_.Unlock(); }
56+
void lock() ABSL_EXCLUSIVE_LOCK_FUNCTION(lock_) { lock_.lock(); }
57+
inline void Lock() ABSL_EXCLUSIVE_LOCK_FUNCTION(lock_) { lock(); }
58+
59+
void unlock() ABSL_UNLOCK_FUNCTION(lock_) { lock_.unlock(); }
60+
inline void Unlock() ABSL_UNLOCK_FUNCTION(lock_) { unlock(); }
5861

5962
// Returns the flag object for the specified name, or nullptr if not found.
6063
// Will emit a warning if a 'retired' flag is specified.
@@ -87,8 +90,8 @@ namespace {
8790

8891
class FlagRegistryLock {
8992
public:
90-
explicit FlagRegistryLock(FlagRegistry& fr) : fr_(fr) { fr_.Lock(); }
91-
~FlagRegistryLock() { fr_.Unlock(); }
93+
explicit FlagRegistryLock(FlagRegistry& fr) : fr_(fr) { fr_.lock(); }
94+
~FlagRegistryLock() { fr_.unlock(); }
9295

9396
private:
9497
FlagRegistry& fr_;

absl/strings/internal/cordz_info.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,14 +378,14 @@ void CordzInfo::Untrack() {
378378

379379
void CordzInfo::Lock(MethodIdentifier method)
380380
ABSL_EXCLUSIVE_LOCK_FUNCTION(mutex_) {
381-
mutex_.Lock();
381+
mutex_.lock();
382382
update_tracker_.LossyAdd(method);
383383
assert(rep_);
384384
}
385385

386386
void CordzInfo::Unlock() ABSL_UNLOCK_FUNCTION(mutex_) {
387387
bool tracked = rep_ != nullptr;
388-
mutex_.Unlock();
388+
mutex_.unlock();
389389
if (!tracked) {
390390
Untrack();
391391
}

absl/synchronization/lifetime_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,12 @@ ABSL_CONST_INIT absl::Mutex early_const_init_mutex(absl::kConstInit);
148148
// before the constructors of either grab_lock or check_still_locked are run.)
149149
extern absl::Mutex const_init_sanity_mutex;
150150
OnConstruction grab_lock([]() ABSL_NO_THREAD_SAFETY_ANALYSIS {
151-
const_init_sanity_mutex.Lock();
151+
const_init_sanity_mutex.lock();
152152
});
153153
ABSL_CONST_INIT absl::Mutex const_init_sanity_mutex(absl::kConstInit);
154154
OnConstruction check_still_locked([]() ABSL_NO_THREAD_SAFETY_ANALYSIS {
155155
const_init_sanity_mutex.AssertHeld();
156-
const_init_sanity_mutex.Unlock();
156+
const_init_sanity_mutex.unlock();
157157
});
158158
#endif // defined(__clang__) || !(defined(_MSC_VER) && _MSC_VER > 1900)
159159

absl/synchronization/mutex.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2760,7 +2760,7 @@ void CondVar::SignalAll() {
27602760
void ReleasableMutexLock::Release() {
27612761
ABSL_RAW_CHECK(this->mu_ != nullptr,
27622762
"ReleasableMutexLock::Release may only be called once");
2763-
this->mu_->Unlock();
2763+
this->mu_->unlock();
27642764
this->mu_ = nullptr;
27652765
}
27662766

absl/synchronization/mutex.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -599,11 +599,11 @@ class ABSL_SCOPED_LOCKABLE MutexLock {
599599
public:
600600
// Constructors
601601

602-
// Calls `mu->Lock()` and returns when that call returns. That is, `*mu` is
602+
// Calls `mu->lock()` and returns when that call returns. That is, `*mu` is
603603
// guaranteed to be locked when this object is constructed. Requires that
604604
// `mu` be dereferenceable.
605605
explicit MutexLock(Mutex& mu) ABSL_EXCLUSIVE_LOCK_FUNCTION(mu) : mu_(mu) {
606-
this->mu_.Lock();
606+
this->mu_.lock();
607607
}
608608

609609
explicit MutexLock(Mutex* absl_nonnull mu) ABSL_EXCLUSIVE_LOCK_FUNCTION(mu)
@@ -623,7 +623,7 @@ class ABSL_SCOPED_LOCKABLE MutexLock {
623623
MutexLock& operator=(const MutexLock&) = delete;
624624
MutexLock& operator=(MutexLock&&) = delete;
625625

626-
~MutexLock() ABSL_UNLOCK_FUNCTION() { this->mu_.Unlock(); }
626+
~MutexLock() ABSL_UNLOCK_FUNCTION() { this->mu_.unlock(); }
627627

628628
private:
629629
Mutex& mu_;
@@ -657,7 +657,7 @@ class ABSL_SCOPED_LOCKABLE ReaderMutexLock {
657657
ReaderMutexLock& operator=(const ReaderMutexLock&) = delete;
658658
ReaderMutexLock& operator=(ReaderMutexLock&&) = delete;
659659

660-
~ReaderMutexLock() ABSL_UNLOCK_FUNCTION() { this->mu_.ReaderUnlock(); }
660+
~ReaderMutexLock() ABSL_UNLOCK_FUNCTION() { this->mu_.unlock_shared(); }
661661

662662
private:
663663
Mutex& mu_;
@@ -1049,7 +1049,7 @@ class ABSL_SCOPED_LOCKABLE MutexLockMaybe {
10491049
ABSL_EXCLUSIVE_LOCK_FUNCTION(mu)
10501050
: mu_(mu) {
10511051
if (this->mu_ != nullptr) {
1052-
this->mu_->Lock();
1052+
this->mu_->lock();
10531053
}
10541054
}
10551055

@@ -1063,7 +1063,7 @@ class ABSL_SCOPED_LOCKABLE MutexLockMaybe {
10631063

10641064
~MutexLockMaybe() ABSL_UNLOCK_FUNCTION() {
10651065
if (this->mu_ != nullptr) {
1066-
this->mu_->Unlock();
1066+
this->mu_->unlock();
10671067
}
10681068
}
10691069

@@ -1084,7 +1084,7 @@ class ABSL_SCOPED_LOCKABLE ReleasableMutexLock {
10841084
explicit ReleasableMutexLock(Mutex* absl_nonnull mu)
10851085
ABSL_EXCLUSIVE_LOCK_FUNCTION(mu)
10861086
: mu_(mu) {
1087-
this->mu_->Lock();
1087+
this->mu_->lock();
10881088
}
10891089

10901090
explicit ReleasableMutexLock(Mutex* absl_nonnull mu, const Condition& cond)
@@ -1095,7 +1095,7 @@ class ABSL_SCOPED_LOCKABLE ReleasableMutexLock {
10951095

10961096
~ReleasableMutexLock() ABSL_UNLOCK_FUNCTION() {
10971097
if (this->mu_ != nullptr) {
1098-
this->mu_->Unlock();
1098+
this->mu_->unlock();
10991099
}
11001100
}
11011101

absl/synchronization/mutex_benchmark.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ BENCHMARK(BM_ReaderLock)->UseRealTime()->Threads(1)->ThreadPerCpu();
4646
void BM_TryLock(benchmark::State& state) {
4747
absl::Mutex mu;
4848
for (auto _ : state) {
49-
if (mu.TryLock()) {
50-
mu.Unlock();
49+
if (mu.try_lock()) {
50+
mu.unlock();
5151
}
5252
}
5353
}
@@ -56,8 +56,8 @@ BENCHMARK(BM_TryLock);
5656
void BM_ReaderTryLock(benchmark::State& state) {
5757
static absl::NoDestructor<absl::Mutex> mu;
5858
for (auto _ : state) {
59-
if (mu->ReaderTryLock()) {
60-
mu->ReaderUnlock();
59+
if (mu->try_lock_shared()) {
60+
mu->unlock_shared();
6161
}
6262
}
6363
}
@@ -273,7 +273,7 @@ void BM_ConditionWaiters(benchmark::State& state) {
273273
init->DecrementCount();
274274
m->LockWhen(absl::Condition(
275275
static_cast<bool (*)(int*)>([](int* v) { return *v == 0; }), p));
276-
m->Unlock();
276+
m->unlock();
277277
}
278278
};
279279

@@ -299,15 +299,15 @@ void BM_ConditionWaiters(benchmark::State& state) {
299299
init.Wait();
300300

301301
for (auto _ : state) {
302-
mu.Lock();
303-
mu.Unlock(); // Each unlock requires Condition evaluation for our waiters.
302+
mu.lock();
303+
mu.unlock(); // Each unlock requires Condition evaluation for our waiters.
304304
}
305305

306-
mu.Lock();
306+
mu.lock();
307307
for (int i = 0; i < num_classes; i++) {
308308
equivalence_classes[i] = 0;
309309
}
310-
mu.Unlock();
310+
mu.unlock();
311311
}
312312

313313
// Some configurations have higher thread limits than others.

0 commit comments

Comments
 (0)