refactor: use std::scoped_lock inplace of std::lock_guard

This commit is contained in:
sithlord48
2025-06-15 20:15:07 -04:00
committed by Nick Bolton
parent 5fd4d93f7f
commit c15214aee7
16 changed files with 92 additions and 92 deletions

View File

@ -70,7 +70,7 @@ void EventQueue::loop()
void EventQueue::adoptBuffer(IEventQueueBuffer *buffer)
{
std::lock_guard<std::mutex> lock(m_mutex);
std::scoped_lock lock{m_mutex};
LOG((CLOG_DEBUG "adopting new buffer"));
@ -139,7 +139,7 @@ bool EventQueue::processEvent(Event &event, double timeout, Stopwatch &timer)
return true;
case IEventQueueBuffer::kUser: {
std::lock_guard<std::mutex> lock(m_mutex);
std::scoped_lock lock{m_mutex};
event = removeEvent(dataID);
return true;
}
@ -195,7 +195,7 @@ void EventQueue::addEvent(const Event &event)
void EventQueue::addEventToBuffer(const Event &event)
{
std::lock_guard<std::mutex> lock(m_mutex);
std::scoped_lock lock{m_mutex};
// store the event's data locally
auto eventID = saveEvent(event);
@ -216,7 +216,7 @@ EventQueueTimer *EventQueue::newTimer(double duration, void *target)
if (target == nullptr) {
target = timer;
}
std::lock_guard<std::mutex> lock(m_mutex);
std::scoped_lock lock{m_mutex};
m_timers.insert(timer);
// initial duration is requested duration plus whatever's on
// the clock currently because the latter will be subtracted
@ -233,7 +233,7 @@ EventQueueTimer *EventQueue::newOneShotTimer(double duration, void *target)
if (target == nullptr) {
target = timer;
}
std::lock_guard<std::mutex> lock(m_mutex);
std::scoped_lock lock{m_mutex};
m_timers.insert(timer);
// initial duration is requested duration plus whatever's on
// the clock currently because the latter will be subtracted
@ -244,7 +244,7 @@ EventQueueTimer *EventQueue::newOneShotTimer(double duration, void *target)
void EventQueue::deleteTimer(EventQueueTimer *timer)
{
std::lock_guard<std::mutex> lock(m_mutex);
std::scoped_lock lock{m_mutex};
for (auto index = m_timerQueue.begin(); index != m_timerQueue.end(); ++index) {
if (index->getTimer() == timer) {
m_timerQueue.erase(index);
@ -259,7 +259,7 @@ void EventQueue::deleteTimer(EventQueueTimer *timer)
void EventQueue::adoptHandler(EventTypes type, void *target, IEventJob *handler)
{
std::lock_guard<std::mutex> lock(m_mutex);
std::scoped_lock lock{m_mutex};
m_handlers[target][type].reset(handler);
}
@ -267,7 +267,7 @@ void EventQueue::removeHandler(EventTypes type, void *target)
{
std::unique_ptr<IEventJob> handler;
{
std::lock_guard<std::mutex> lock(m_mutex);
std::scoped_lock lock{m_mutex};
HandlerTable::iterator index = m_handlers.find(target);
if (index != m_handlers.end()) {
TypeHandlerTable &typeHandlers = index->second;
@ -285,7 +285,7 @@ void EventQueue::removeHandlers(void *target)
{
std::vector<std::unique_ptr<IEventJob>> handlers;
{
std::lock_guard<std::mutex> lock(m_mutex);
std::scoped_lock lock{m_mutex};
HandlerTable::iterator index = m_handlers.find(target);
if (index != m_handlers.end()) {
// copy to handlers array and clear table for target
@ -306,7 +306,7 @@ bool EventQueue::isEmpty() const
IEventJob *EventQueue::getHandler(EventTypes type, void *target) const
{
std::lock_guard<std::mutex> lock(m_mutex);
std::scoped_lock lock{m_mutex};
if (HandlerTable::const_iterator index = m_handlers.find(target); index != m_handlers.end()) {
const TypeHandlerTable &typeHandlers = index->second;
TypeHandlerTable::const_iterator index2 = typeHandlers.find(type);