refactor: Simplify lock_guard usage by removing explicit mutex type

This commit is contained in:
Nick Bolton 2025-03-10 13:35:42 +00:00 committed by Chris Rizzitello
parent 3bcc1e11ed
commit 24d1d4e620
5 changed files with 18 additions and 18 deletions

View file

@ -40,7 +40,7 @@ AppUtilWindows::AppUtilWindows(IEventQueue *events) : m_events(events), m_exitMo
// Waiting for the event loop start prevents race condition in fast fail scenario,
// where the dtor is called just before the event loop starts.
LOG_DEBUG("waiting for event thread to start");
std::unique_lock<std::mutex> lock(m_eventThreadStartedMutex);
std::unique_lock lock(m_eventThreadStartedMutex);
m_eventThreadStartedCond.wait(lock, [this] { return m_eventThreadRunning; });
LOG_DEBUG("event thread started");
}
@ -269,7 +269,7 @@ void AppUtilWindows::eventLoop()
LOG_DEBUG("windows event loop running");
{
std::lock_guard<std::mutex> lock(m_eventThreadStartedMutex);
std::lock_guard lock(m_eventThreadStartedMutex);
m_eventThreadRunning = true;
}
m_eventThreadStartedCond.notify_one();

View file

@ -234,7 +234,7 @@ TCPSocket::EJobResult SecureSocket::doWrite()
int SecureSocket::secureRead(void *buffer, int size, int &read)
{
std::lock_guard<std::mutex> ssl_lock{ssl_mutex_};
std::lock_guard ssl_lock{ssl_mutex_};
if (m_ssl->m_ssl != NULL) {
LOG((CLOG_DEBUG2 "reading secure socket"));
@ -261,7 +261,7 @@ int SecureSocket::secureRead(void *buffer, int size, int &read)
int SecureSocket::secureWrite(const void *buffer, int size, int &wrote)
{
std::lock_guard<std::mutex> ssl_lock{ssl_mutex_};
std::lock_guard ssl_lock{ssl_mutex_};
if (m_ssl->m_ssl != NULL) {
LOG((CLOG_DEBUG2 "writing secure socket: %p", this));
@ -294,7 +294,7 @@ bool SecureSocket::isSecureReady()
void SecureSocket::initSsl(bool server)
{
std::lock_guard<std::mutex> ssl_lock{ssl_mutex_};
std::lock_guard ssl_lock{ssl_mutex_};
m_ssl = new Ssl();
m_ssl->m_context = NULL;
@ -305,7 +305,7 @@ void SecureSocket::initSsl(bool server)
bool SecureSocket::loadCertificates(std::string &filename)
{
std::lock_guard<std::mutex> ssl_lock{ssl_mutex_};
std::lock_guard ssl_lock{ssl_mutex_};
if (filename.empty()) {
SslLogger::logError("tls certificate is not specified");
@ -396,7 +396,7 @@ void SecureSocket::createSSL()
void SecureSocket::freeSSL()
{
std::lock_guard<std::mutex> ssl_lock{ssl_mutex_};
std::lock_guard ssl_lock{ssl_mutex_};
isFatal(true);
// take socket from multiplexer ASAP otherwise the race condition
@ -421,7 +421,7 @@ void SecureSocket::freeSSL()
int SecureSocket::secureAccept(int socket)
{
std::lock_guard<std::mutex> ssl_lock{ssl_mutex_};
std::lock_guard ssl_lock{ssl_mutex_};
createSSL();
@ -489,7 +489,7 @@ int SecureSocket::secureConnect(int socket)
return -1;
}
std::lock_guard<std::mutex> ssl_lock{ssl_mutex_};
std::lock_guard ssl_lock{ssl_mutex_};
createSSL();

View file

@ -65,7 +65,7 @@ void EiEventQueueBuffer::waitForEvent(double timeout_in_ms)
int retval = poll(pfds, POLLFD_COUNT, timeout);
if (retval > 0) {
if (pfds[EIFD].revents & POLLIN) {
std::lock_guard<std::mutex> lock(mutex_);
std::lock_guard lock(mutex_);
// libei doesn't allow ei_event_ref() because events are
// supposed to be short-lived only. So instead, we create an NULL-data
@ -103,7 +103,7 @@ IEventQueueBuffer::Type EiEventQueueBuffer::getEvent(Event &event, uint32_t &dat
// we just have a "something happened" event on the ei fd and the rest is
// handled by the EiScreen.
//
std::lock_guard<std::mutex> lock(mutex_);
std::lock_guard lock(mutex_);
auto pair = queue_.front();
queue_.pop();
@ -120,7 +120,7 @@ IEventQueueBuffer::Type EiEventQueueBuffer::getEvent(Event &event, uint32_t &dat
bool EiEventQueueBuffer::addEvent(uint32_t dataID)
{
std::lock_guard<std::mutex> lock(mutex_);
std::lock_guard lock(mutex_);
queue_.push({false, dataID});
// tickle the pipe so our read thread wakes up
@ -132,7 +132,7 @@ bool EiEventQueueBuffer::addEvent(uint32_t dataID)
bool EiEventQueueBuffer::isEmpty() const
{
std::lock_guard<std::mutex> lock(mutex_);
std::lock_guard lock(mutex_);
return queue_.empty();
}

View file

@ -719,7 +719,7 @@ void EiScreen::handle_portal_session_closed(const Event &event, void *)
void EiScreen::handleSystemEvent(const Event &sysevent, void *)
{
std::lock_guard<std::mutex> lock(mutex_);
std::lock_guard lock(mutex_);
bool disconnected = false;
// Only one ei_dispatch per system event, see the comment in

View file

@ -41,7 +41,7 @@ void OSXEventQueueBuffer::init()
void OSXEventQueueBuffer::waitForEvent(double timeout)
{
std::unique_lock<std::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
if (m_dataQueue.empty()) {
auto duration = std::chrono::duration<double>(timeout);
LOG_DEBUG2("waiting for event, timeout: %f seconds", timeout);
@ -53,7 +53,7 @@ void OSXEventQueueBuffer::waitForEvent(double timeout)
IEventQueueBuffer::Type OSXEventQueueBuffer::getEvent(Event &event, uint32_t &dataID)
{
std::unique_lock<std::mutex> lock(m_mutex);
std::unique_lock lock(m_mutex);
if (m_dataQueue.empty()) {
LOG_DEBUG2("no events in queue");
return kNone;
@ -71,7 +71,7 @@ bool OSXEventQueueBuffer::addEvent(uint32_t dataID)
{
// Use GCD to dispatch event addition on the main queue
dispatch_async(dispatch_get_main_queue(), ^{
std::lock_guard<std::mutex> lock(this->m_mutex);
std::lock_guard lock(this->m_mutex);
LOG_DEBUG2("adding user event with dataID: %u", dataID);
this->m_dataQueue.push(dataID);
this->m_cond.notify_one();
@ -84,7 +84,7 @@ bool OSXEventQueueBuffer::addEvent(uint32_t dataID)
bool OSXEventQueueBuffer::isEmpty() const
{
std::lock_guard<std::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);
bool empty = m_dataQueue.empty();
LOG_DEBUG2("queue is %s", empty ? "empty" : "not empty");
return empty;