Skip to content

Commit 8b1f88d

Browse files
authored
clean-up: use Mutex reference and change lock interface p2 (#42673)
Replace absl::MutexLock::MutexLock(Mutex*) constructor with absl::MutexLock::MutexLock(Mutex&) Similar to #41948 Commit Message: Additional Description: Risk Level: Testing: Docs Changes: Release Notes: Platform Specific Features: --------- Signed-off-by: Boteng Yao <boteng@google.com>
1 parent 692bc00 commit 8b1f88d

12 files changed

Lines changed: 66 additions & 66 deletions

File tree

source/common/common/thread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class AtomicPtrArray : NonCopyable {
129129

130130
// First, use an atomic load to see if the object has already been allocated.
131131
if (atomic_ref.load() == nullptr) {
132-
absl::MutexLock lock(&mutex_);
132+
absl::MutexLock lock(mutex_);
133133

134134
// If that fails, check again under lock as two threads might have raced
135135
// to create the object.

source/common/stats/symbol_table.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ class StatNameSet {
10451045
* @return The StatName for str.
10461046
*/
10471047
StatName add(absl::string_view str) {
1048-
absl::MutexLock lock(&mutex_);
1048+
absl::MutexLock lock(mutex_);
10491049
return pool_.add(str);
10501050
}
10511051

source/extensions/clusters/redis/redis_cluster_lb.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ bool RedisClusterLoadBalancerFactory::onClusterSlotUpdate(ClusterSlotsSharedPtr&
7979
void RedisClusterLoadBalancerFactory::onHostHealthUpdate() {
8080
ShardVectorSharedPtr current_shard_vector;
8181
{
82-
absl::ReaderMutexLock lock(&mutex_);
82+
absl::ReaderMutexLock lock(mutex_);
8383
current_shard_vector = shard_vector_;
8484
}
8585

@@ -102,7 +102,7 @@ void RedisClusterLoadBalancerFactory::onHostHealthUpdate() {
102102
}
103103

104104
Upstream::LoadBalancerPtr RedisClusterLoadBalancerFactory::create(Upstream::LoadBalancerParams) {
105-
absl::ReaderMutexLock lock(&mutex_);
105+
absl::ReaderMutexLock lock(mutex_);
106106
return std::make_unique<RedisClusterLoadBalancer>(slot_array_, shard_vector_, random_);
107107
}
108108

source/extensions/http/cache/simple_http_cache/simple_http_cache.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ void SimpleHttpCache::updateHeaders(const LookupContext& lookup_context,
211211
}
212212

213213
SimpleHttpCache::Entry SimpleHttpCache::lookup(const LookupRequest& request) {
214-
absl::ReaderMutexLock lock(&mutex_);
214+
absl::ReaderMutexLock lock(mutex_);
215215
auto iter = map_.find(request.key());
216216
if (iter == map_.end()) {
217217
return Entry{};

source/extensions/load_balancing_policies/common/thread_aware_lb_impl.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ LoadBalancerPtr ThreadAwareLoadBalancerBase::LoadBalancerFactoryImpl::create(Loa
224224

225225
// We must protect current_lb_ via a RW lock since it is accessed and written to by multiple
226226
// threads. All complex processing has already been precalculated however.
227-
absl::ReaderMutexLock lock(&mutex_);
227+
absl::ReaderMutexLock lock(mutex_);
228228
lb->healthy_per_priority_load_ = healthy_per_priority_load_;
229229
lb->degraded_per_priority_load_ = degraded_per_priority_load_;
230230
lb->per_priority_state_ = per_priority_state_;

source/extensions/network/dns_resolver/getaddrinfo/getaddrinfo.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,18 @@ class GetAddrInfoDnsResolver : public DnsResolver, public Logger::Loggable<Logge
5151

5252
void cancel(CancelReason) override {
5353
ENVOY_LOG(trace, "cancelling query [{}]", dns_name_);
54-
absl::MutexLock lock(&mutex_);
54+
absl::MutexLock lock(mutex_);
5555
cancelled_ = true;
5656
}
5757

5858
void addTrace(uint8_t trace) override {
59-
absl::MutexLock lock(&mutex_);
59+
absl::MutexLock lock(mutex_);
6060
traces_.push_back(
6161
Trace{trace, std::chrono::steady_clock::now()}); // NO_CHECK_FORMAT(real_time)
6262
}
6363

6464
std::string getTraces() override {
65-
absl::MutexLock lock(&mutex_);
65+
absl::MutexLock lock(mutex_);
6666
std::vector<std::string> string_traces;
6767
string_traces.reserve(traces_.size());
6868
std::transform(traces_.begin(), traces_.end(), std::back_inserter(string_traces),
@@ -74,7 +74,7 @@ class GetAddrInfoDnsResolver : public DnsResolver, public Logger::Loggable<Logge
7474
}
7575

7676
bool isCancelled() {
77-
absl::MutexLock lock(&mutex_);
77+
absl::MutexLock lock(mutex_);
7878
return cancelled_;
7979
}
8080

test/extensions/watchdog/profile_action/profile_action_test.cc

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ TEST_F(ProfileActionTest, CanDoSingleProfile) {
112112
// Check that we can do at least a single profile
113113
dispatcher_->post([&tid_ltt_pairs, &now, this]() -> void {
114114
action_->run(envoy::config::bootstrap::v3::Watchdog::WatchdogAction::MISS, tid_ltt_pairs, now);
115-
absl::MutexLock lock(&mutex_);
115+
absl::MutexLock lock(mutex_);
116116
outstanding_notifies_ += 1;
117117
});
118118

119-
absl::MutexLock lock(&mutex_);
119+
absl::MutexLock lock(mutex_);
120120
waitForOutstandingNotify();
121121
time_system_->advanceTimeWait(std::chrono::seconds(2));
122122

@@ -151,11 +151,11 @@ TEST_F(ProfileActionTest, CanDoMultipleProfiles) {
151151
// Check that we can do at least a single profile
152152
dispatcher_->post([&tid_ltt_pairs, &now, this]() -> void {
153153
action_->run(envoy::config::bootstrap::v3::Watchdog::WatchdogAction::MISS, tid_ltt_pairs, now);
154-
absl::MutexLock lock(&mutex_);
154+
absl::MutexLock lock(mutex_);
155155
outstanding_notifies_ += 1;
156156
});
157157

158-
absl::MutexLock lock(&mutex_);
158+
absl::MutexLock lock(mutex_);
159159
waitForOutstandingNotify();
160160
time_system_->advanceTimeWait(std::chrono::seconds(2));
161161

@@ -169,7 +169,7 @@ TEST_F(ProfileActionTest, CanDoMultipleProfiles) {
169169
// Check we can do multiple profiles
170170
dispatcher_->post([&tid_ltt_pairs, &now, this]() -> void {
171171
action_->run(envoy::config::bootstrap::v3::Watchdog::WatchdogAction::MISS, tid_ltt_pairs, now);
172-
absl::MutexLock lock(&mutex_);
172+
absl::MutexLock lock(mutex_);
173173
outstanding_notifies_ += 1;
174174
});
175175

@@ -210,11 +210,11 @@ TEST_F(ProfileActionTest, CannotTriggerConcurrentProfiles) {
210210
// This subsequent call should fail since the one prior starts a profile.
211211
action_->run(envoy::config::bootstrap::v3::Watchdog::WatchdogAction::MISS, tid_ltt_pairs, now);
212212

213-
absl::MutexLock lock(&mutex_);
213+
absl::MutexLock lock(mutex_);
214214
outstanding_notifies_ += 1;
215215
});
216216

217-
absl::MutexLock lock(&mutex_);
217+
absl::MutexLock lock(mutex_);
218218
waitForOutstandingNotify();
219219
time_system_->advanceTimeWait(std::chrono::seconds(6));
220220

@@ -248,11 +248,11 @@ TEST_F(ProfileActionTest, ShouldNotProfileIfDirectoryDoesNotExist) {
248248

249249
dispatcher_->post([&, this]() -> void {
250250
action_->run(envoy::config::bootstrap::v3::Watchdog::WatchdogAction::MISS, tid_ltt_pairs, now);
251-
absl::MutexLock lock(&mutex_);
251+
absl::MutexLock lock(mutex_);
252252
outstanding_notifies_ += 1;
253253
});
254254

255-
absl::MutexLock lock(&mutex_);
255+
absl::MutexLock lock(mutex_);
256256
waitForOutstandingNotify();
257257
time_system_->advanceTimeWait(std::chrono::seconds(6));
258258

@@ -280,11 +280,11 @@ TEST_F(ProfileActionTest, ShouldNotProfileIfNoTids) {
280280
std::vector<std::pair<Thread::ThreadId, MonotonicTime>> tid_ltt_pairs;
281281
action_->run(envoy::config::bootstrap::v3::Watchdog::WatchdogAction::MISS, tid_ltt_pairs,
282282
api_->timeSource().monotonicTime());
283-
absl::MutexLock lock(&mutex_);
283+
absl::MutexLock lock(mutex_);
284284
outstanding_notifies_ += 1;
285285
});
286286

287-
absl::MutexLock lock(&mutex_);
287+
absl::MutexLock lock(mutex_);
288288
waitForOutstandingNotify();
289289
time_system_->advanceTimeWait(std::chrono::seconds(2));
290290

@@ -316,11 +316,11 @@ TEST_F(ProfileActionTest, ShouldSaturatedMaxProfiles) {
316316

317317
dispatcher_->post([&, this]() -> void {
318318
action_->run(envoy::config::bootstrap::v3::Watchdog::WatchdogAction::MISS, tid_ltt_pairs, now);
319-
absl::MutexLock lock(&mutex_);
319+
absl::MutexLock lock(mutex_);
320320
outstanding_notifies_ += 1;
321321
});
322322

323-
absl::MutexLock lock(&mutex_);
323+
absl::MutexLock lock(mutex_);
324324
waitForOutstandingNotify();
325325
time_system_->advanceTimeWait(std::chrono::seconds(2));
326326

@@ -335,7 +335,7 @@ TEST_F(ProfileActionTest, ShouldSaturatedMaxProfiles) {
335335
// Do another run of the watchdog action. It shouldn't have run again.
336336
dispatcher_->post([&, this]() -> void {
337337
action_->run(envoy::config::bootstrap::v3::Watchdog::WatchdogAction::MISS, tid_ltt_pairs, now);
338-
absl::MutexLock lock(&mutex_);
338+
absl::MutexLock lock(mutex_);
339339
outstanding_notifies_ += 1;
340340
});
341341

@@ -375,12 +375,12 @@ TEST_F(ProfileActionTest, ShouldUpdateCountersCorrectly) {
375375
dispatcher_->post([this, &tid_ltt_pairs]() -> void {
376376
action_->run(envoy::config::bootstrap::v3::Watchdog::WatchdogAction::MISS, tid_ltt_pairs,
377377
api_->timeSource().monotonicTime());
378-
absl::MutexLock lock(&mutex_);
378+
absl::MutexLock lock(mutex_);
379379
outstanding_notifies_ += 1;
380380
});
381381

382382
{
383-
absl::MutexLock lock(&mutex_);
383+
absl::MutexLock lock(mutex_);
384384
waitForOutstandingNotify();
385385
time_system_->advanceTimeWait(std::chrono::seconds(2));
386386
}
@@ -396,12 +396,12 @@ TEST_F(ProfileActionTest, ShouldUpdateCountersCorrectly) {
396396

397397
dispatcher_->post([this, &tid_ltt_pairs, &now]() -> void {
398398
action_->run(envoy::config::bootstrap::v3::Watchdog::WatchdogAction::MISS, tid_ltt_pairs, now);
399-
absl::MutexLock lock(&mutex_);
399+
absl::MutexLock lock(mutex_);
400400
outstanding_notifies_ += 1;
401401
});
402402

403403
{
404-
absl::MutexLock lock(&mutex_);
404+
absl::MutexLock lock(mutex_);
405405
waitForOutstandingNotify();
406406
time_system_->advanceTimeWait(std::chrono::seconds(2));
407407
}

test/test_common/file_system_for_test.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct MemFileInfo {
1717
SystemTime access_time_;
1818
SystemTime modify_time_;
1919
FileInfo toFileInfo(absl::string_view path) {
20-
absl::MutexLock lock(&lock_);
20+
absl::MutexLock lock(lock_);
2121
return {
2222
std::string{fileSystemForTest().splitPathFromFilename(path).value().file_},
2323
data_.length(),
@@ -43,14 +43,14 @@ class MemfileImpl : public FileSharedImpl {
4343
open_ = true;
4444
if (flags_.test(File::Operation::Write) && !flags_.test(File::Operation::Append) &&
4545
!flags_.test(File::Operation::KeepExistingData)) {
46-
absl::MutexLock l(&info_->lock_);
46+
absl::MutexLock l(info_->lock_);
4747
info_->data_.clear();
4848
}
4949
return resultSuccess(true);
5050
}
5151

5252
Api::IoCallSizeResult write(absl::string_view buffer) override {
53-
absl::MutexLock l(&info_->lock_);
53+
absl::MutexLock l(info_->lock_);
5454
info_->data_.append(std::string(buffer));
5555
const ssize_t size = info_->data_.size();
5656
return resultSuccess(size);
@@ -73,7 +73,7 @@ class MemfileImpl : public FileSharedImpl {
7373
};
7474

7575
Api::IoCallSizeResult MemfileImpl::pread(void* buf, uint64_t count, uint64_t offset) {
76-
absl::MutexLock l(&info_->lock_);
76+
absl::MutexLock l(info_->lock_);
7777
if (!flags_.test(File::Operation::Read)) {
7878
return resultFailure<ssize_t>(-1, EBADF);
7979
}
@@ -88,7 +88,7 @@ Api::IoCallSizeResult MemfileImpl::pread(void* buf, uint64_t count, uint64_t off
8888
}
8989

9090
Api::IoCallSizeResult MemfileImpl::pwrite(const void* buf, uint64_t count, uint64_t offset) {
91-
absl::MutexLock l(&info_->lock_);
91+
absl::MutexLock l(info_->lock_);
9292
if (!flags_.test(File::Operation::Write)) {
9393
return resultFailure<ssize_t>(-1, EBADF);
9494
}
@@ -111,7 +111,7 @@ Api::IoCallResult<FileInfo> MemfileImpl::info() { return resultSuccess(info_->to
111111

112112
Api::IoCallResult<FileInfo> MemfileInstanceImpl::stat(absl::string_view path) {
113113
{
114-
absl::MutexLock m(&lock_);
114+
absl::MutexLock m(lock_);
115115
auto it = files_.find(path);
116116
if (it != files_.end()) {
117117
ASSERT(use_memfiles_);
@@ -135,7 +135,7 @@ MemfileInstanceImpl& fileSystemForTest() {
135135

136136
FilePtr MemfileInstanceImpl::createFile(const FilePathAndType& file_info) {
137137
const std::string& path = file_info.path_;
138-
absl::MutexLock m(&lock_);
138+
absl::MutexLock m(lock_);
139139
if (!use_memfiles_) {
140140
return file_system_->createFile(file_info);
141141
}
@@ -158,11 +158,11 @@ FilePtr MemfileInstanceImpl::createFile(const FilePathAndType& file_info) {
158158

159159
ssize_t MemfileInstanceImpl::fileSize(const std::string& path) {
160160
{
161-
absl::MutexLock m(&lock_);
161+
absl::MutexLock m(lock_);
162162
auto it = files_.find(path);
163163
if (it != files_.end()) {
164164
ASSERT(use_memfiles_);
165-
absl::MutexLock n(&it->second->lock_);
165+
absl::MutexLock n(it->second->lock_);
166166
return it->second->data_.size();
167167
}
168168
}
@@ -171,10 +171,10 @@ ssize_t MemfileInstanceImpl::fileSize(const std::string& path) {
171171

172172
absl::StatusOr<std::string> MemfileInstanceImpl::fileReadToEnd(const std::string& path) {
173173
{
174-
absl::MutexLock m(&lock_);
174+
absl::MutexLock m(lock_);
175175
auto it = files_.find(path);
176176
if (it != files_.end()) {
177-
absl::MutexLock n(&it->second->lock_);
177+
absl::MutexLock n(it->second->lock_);
178178
ASSERT(use_memfiles_);
179179
return it->second->data_;
180180
}
@@ -184,7 +184,7 @@ absl::StatusOr<std::string> MemfileInstanceImpl::fileReadToEnd(const std::string
184184

185185
void MemfileInstanceImpl::renameFile(const std::string& old_name, const std::string& new_name) {
186186
{
187-
absl::MutexLock m(&lock_);
187+
absl::MutexLock m(lock_);
188188
// It's easy enough to change the key to the hash set, but most instances of
189189
// renameFile are to trigger file watches in core code, and those are not
190190
// mem-file-aware.

test/test_common/logging.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,18 @@ void LogRecordingSink::log(absl::string_view msg, const spdlog::details::log_msg
5353
previousDelegate()->log(msg, log_msg);
5454

5555
if (enabled_) {
56-
absl::MutexLock ml(&mtx_);
56+
absl::MutexLock ml(mtx_);
5757
messages_.push_back(std::string(msg));
5858
}
5959

60-
absl::MutexLock ml(&exp_mtx_);
60+
absl::MutexLock ml(exp_mtx_);
6161
for (auto* expect : expectations_) {
6262
expect->on_log_(static_cast<Logger::Logger::Levels>(log_msg.level), std::string(msg));
6363
}
6464
}
6565

6666
const std::vector<std::string> LogRecordingSink::messages() const {
67-
absl::MutexLock ml(&mtx_);
67+
absl::MutexLock ml(mtx_);
6868
std::vector<std::string> copy(messages_);
6969
return copy;
7070
}
@@ -77,17 +77,17 @@ void LogRecordingSink::start() {
7777
void LogRecordingSink::stop() {
7878
ASSERT(enabled_);
7979
enabled_ = false;
80-
absl::MutexLock ml(&mtx_);
80+
absl::MutexLock ml(mtx_);
8181
messages_.clear();
8282
}
8383

8484
void LogRecordingSink::addExpectation(LogExpectation* exp) {
85-
absl::MutexLock ml(&exp_mtx_);
85+
absl::MutexLock ml(exp_mtx_);
8686
expectations_.insert(exp);
8787
}
8888

8989
void LogRecordingSink::removeExpectation(LogExpectation* exp) {
90-
absl::MutexLock ml(&exp_mtx_);
90+
absl::MutexLock ml(exp_mtx_);
9191
expectations_.erase(exp);
9292
}
9393

0 commit comments

Comments
 (0)