Let lock_guard deduce its template argument
No functional change, this is a cleanup.
With C++17, it's no longer necessary to specify the teplate argument
when it can be deduced from the types of constructor arguments. This
allows de-cluttering our locking statements.
To avoid typos, this patch was mechanically generated:
perl -p -i -e 's/std::lock_guard<std::mutex>/std::lock_guard/g' \
$(find . -name '*.cpp' -o -name '*.h')
Change-Id: Ibb15d9a6c5b1c861d81353e47d25474eb1d4c2df
diff --git a/libnetdutils/Log.cpp b/libnetdutils/Log.cpp
index 98f2d13..07d5952 100644
--- a/libnetdutils/Log.cpp
+++ b/libnetdutils/Log.cpp
@@ -202,7 +202,7 @@
break;
}
- std::lock_guard<std::shared_mutex> guard(mLock);
+ std::lock_guard guard(mLock);
mEntries.push_back(makeTimestampedEntry(entry));
while (mEntries.size() > mMaxEntries) mEntries.pop_front();
}
diff --git a/libnetdutils/include/netdutils/OperationLimiter.h b/libnetdutils/include/netdutils/OperationLimiter.h
index 633536b..992a849 100644
--- a/libnetdutils/include/netdutils/OperationLimiter.h
+++ b/libnetdutils/include/netdutils/OperationLimiter.h
@@ -60,7 +60,7 @@
// Note: each successful start(key) must be matched by exactly one call to
// finish(key).
bool start(KeyType key) EXCLUDES(mMutex) {
- std::lock_guard<std::mutex> lock(mMutex);
+ std::lock_guard lock(mMutex);
auto& cnt = mCounters[key]; // operator[] creates new entries as needed.
if (cnt >= mLimitPerKey) {
// Oh, no!
@@ -73,7 +73,7 @@
// Decrements the number of operations in progress accounted to |key|.
// See usage notes on start().
void finish(KeyType key) EXCLUDES(mMutex) {
- std::lock_guard<std::mutex> lock(mMutex);
+ std::lock_guard lock(mMutex);
auto it = mCounters.find(key);
if (it == mCounters.end()) {
LOG(FATAL_WITHOUT_ABORT) << "Decremented non-existent counter for key=" << key;