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/tests/dns_responder/dns_responder.cpp b/tests/dns_responder/dns_responder.cpp
index 0ba3388..615e6f6 100644
--- a/tests/dns_responder/dns_responder.cpp
+++ b/tests/dns_responder/dns_responder.cpp
@@ -538,7 +538,7 @@
void DNSResponder::addMapping(const char* name, ns_type type,
const char* addr) {
- std::lock_guard<std::mutex> lock(mappings_mutex_);
+ std::lock_guard lock(mappings_mutex_);
auto it = mappings_.find(QueryKey(name, type));
if (it != mappings_.end()) {
ALOGI("Overwriting mapping for (%s, %s), previous address %s, new "
@@ -553,7 +553,7 @@
}
void DNSResponder::removeMapping(const char* name, ns_type type) {
- std::lock_guard<std::mutex> lock(mappings_mutex_);
+ std::lock_guard lock(mappings_mutex_);
auto it = mappings_.find(QueryKey(name, type));
if (it != mappings_.end()) {
ALOGI("Cannot remove mapping mapping from (%s, %s), not present", name,
@@ -641,7 +641,7 @@
epoll_fd_ = ep_fd;
socket_ = s;
{
- std::lock_guard<std::mutex> lock(update_mutex_);
+ std::lock_guard lock(update_mutex_);
handler_thread_ = std::thread(&DNSResponder::requestHandler, this);
}
ALOGI("server started successfully");
@@ -649,7 +649,7 @@
}
bool DNSResponder::stopServer() {
- std::lock_guard<std::mutex> lock(update_mutex_);
+ std::lock_guard lock(update_mutex_);
if (!running()) {
ALOGI("server not running");
return false;
@@ -670,12 +670,12 @@
}
std::vector<std::pair<std::string, ns_type >> DNSResponder::queries() const {
- std::lock_guard<std::mutex> lock(queries_mutex_);
+ std::lock_guard lock(queries_mutex_);
return queries_;
}
void DNSResponder::clearQueries() {
- std::lock_guard<std::mutex> lock(queries_mutex_);
+ std::lock_guard lock(queries_mutex_);
queries_.clear();
}
@@ -765,7 +765,7 @@
response_len);
}
{
- std::lock_guard<std::mutex> lock(queries_mutex_);
+ std::lock_guard lock(queries_mutex_);
for (const DNSQuestion& question : header.questions) {
queries_.push_back(make_pair(question.qname.name,
ns_type(question.qtype)));
@@ -808,7 +808,7 @@
bool DNSResponder::addAnswerRecords(const DNSQuestion& question,
std::vector<DNSRecord>* answers) const {
- std::lock_guard<std::mutex> guard(mappings_mutex_);
+ std::lock_guard guard(mappings_mutex_);
auto it = mappings_.find(QueryKey(question.qname.name, question.qtype));
if (it == mappings_.end()) {
// TODO(imaipi): handle correctly
diff --git a/tests/dns_responder/dns_tls_frontend.cpp b/tests/dns_responder/dns_tls_frontend.cpp
index 8c49254..b114280 100644
--- a/tests/dns_responder/dns_tls_frontend.cpp
+++ b/tests/dns_responder/dns_tls_frontend.cpp
@@ -256,7 +256,7 @@
freeaddrinfo(backend_ai_res);
{
- std::lock_guard<std::mutex> lock(update_mutex_);
+ std::lock_guard lock(update_mutex_);
handler_thread_ = std::thread(&DnsTlsFrontend::requestHandler, this);
}
ALOGI("server started successfully");
@@ -356,7 +356,7 @@
}
bool DnsTlsFrontend::stopServer() {
- std::lock_guard<std::mutex> lock(update_mutex_);
+ std::lock_guard lock(update_mutex_);
if (!running()) {
ALOGI("server not running");
return false;
diff --git a/tests/dns_tls_test.cpp b/tests/dns_tls_test.cpp
index ba71f24..cbedc34 100644
--- a/tests/dns_tls_test.cpp
+++ b/tests/dns_tls_test.cpp
@@ -186,13 +186,13 @@
class FakeSocketDelay : public IDnsTlsSocket {
public:
explicit FakeSocketDelay(IDnsTlsSocketObserver* observer) : mObserver(observer) {}
- ~FakeSocketDelay() { std::lock_guard<std::mutex> guard(mLock); }
+ ~FakeSocketDelay() { std::lock_guard guard(mLock); }
static size_t sDelay;
static bool sReverse;
bool query(uint16_t id, const Slice query) override {
ALOGD("FakeSocketDelay got query with ID %d", int(id));
- std::lock_guard<std::mutex> guard(mLock);
+ std::lock_guard guard(mLock);
// Check for duplicate IDs.
EXPECT_EQ(0U, mIds.count(id));
mIds.insert(id);
@@ -209,7 +209,7 @@
private:
void sendResponses() {
- std::lock_guard<std::mutex> guard(mLock);
+ std::lock_guard guard(mLock);
if (sReverse) {
std::reverse(std::begin(mResponses), std::end(mResponses));
}
@@ -423,7 +423,7 @@
~FakeSocketLimited() {
{
ALOGD("~FakeSocketLimited acquiring mLock");
- std::lock_guard<std::mutex> guard(mLock);
+ std::lock_guard guard(mLock);
ALOGD("~FakeSocketLimited acquired mLock");
for (auto& thread : mThreads) {
ALOGD("~FakeSocketLimited joining response thread");
@@ -441,7 +441,7 @@
}
bool query(uint16_t id, const Slice query) override {
ALOGD("FakeSocketLimited::query acquiring mLock");
- std::lock_guard<std::mutex> guard(mLock);
+ std::lock_guard guard(mLock);
ALOGD("FakeSocketLimited::query acquired mLock");
++mQueries;
@@ -462,7 +462,7 @@
void sendClose() {
{
ALOGD("FakeSocketLimited::sendClose acquiring mLock");
- std::lock_guard<std::mutex> guard(mLock);
+ std::lock_guard guard(mLock);
ALOGD("FakeSocketLimited::sendClose acquired mLock");
for (auto& thread : mThreads) {
ALOGD("FakeSocketLimited::sendClose joining response thread");
@@ -536,13 +536,13 @@
mThreads.emplace_back(&IDnsTlsSocketObserver::onResponse, mObserver, make_query(ID + 1, SIZE));
}
~FakeSocketGarbage() {
- std::lock_guard<std::mutex> guard(mLock);
+ std::lock_guard guard(mLock);
for (auto& thread : mThreads) {
thread.join();
}
}
bool query(uint16_t id, const Slice query) override {
- std::lock_guard<std::mutex> guard(mLock);
+ std::lock_guard guard(mLock);
// Return the response twice.
auto echo = make_echo(id, query);
mThreads.emplace_back(&IDnsTlsSocketObserver::onResponse, mObserver, echo);
@@ -608,7 +608,7 @@
unsigned mark,
IDnsTlsSocketObserver* observer,
DnsTlsSessionCache* cache ATTRIBUTE_UNUSED) override {
- std::lock_guard<std::mutex> guard(mLock);
+ std::lock_guard guard(mLock);
keys.emplace(mark, server);
return std::make_unique<T>(observer);
}