refactor: use std::scoped_lock inplace of std::lock_guard
This commit is contained in:
@ -20,7 +20,7 @@ std::mutex s_mutex;
|
||||
|
||||
int ArchString::convStringWCToMB(char *dst, const wchar_t *src, uint32_t n, bool *errors) const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(s_mutex);
|
||||
std::scoped_lock lock{s_mutex};
|
||||
ptrdiff_t len = 0;
|
||||
|
||||
bool dummyErrors;
|
||||
@ -77,7 +77,7 @@ ArchString::EWideCharEncoding ArchString::getWideCharEncoding() const
|
||||
|
||||
int ArchString::convStringMBToWC(wchar_t *dst, const char *src, uint32_t n, bool *errors) const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(s_mutex);
|
||||
std::scoped_lock lock{s_mutex};
|
||||
ptrdiff_t len = 0;
|
||||
wchar_t dummy;
|
||||
|
||||
|
||||
@ -106,14 +106,14 @@ ArchMultithreadPosix::~ArchMultithreadPosix()
|
||||
|
||||
void ArchMultithreadPosix::setNetworkDataForCurrentThread(void *data)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
ArchThreadImpl *thread = find(pthread_self());
|
||||
thread->m_networkData = data;
|
||||
}
|
||||
|
||||
void *ArchMultithreadPosix::getNetworkDataForThread(ArchThread thread)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
return thread->m_networkData;
|
||||
}
|
||||
|
||||
@ -285,7 +285,7 @@ ArchThread ArchMultithreadPosix::newThread(ThreadFunc func, void *data)
|
||||
}
|
||||
|
||||
// note that the child thread will wait until we release this mutex
|
||||
std::lock_guard<std::mutex> lock(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
|
||||
// create thread impl for new thread
|
||||
auto *thread = new ArchThreadImpl;
|
||||
@ -319,7 +319,7 @@ ArchThread ArchMultithreadPosix::newThread(ThreadFunc func, void *data)
|
||||
|
||||
ArchThread ArchMultithreadPosix::newCurrentThread()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
ArchThreadImpl *thread = find(pthread_self());
|
||||
assert(thread != nullptr);
|
||||
return thread;
|
||||
@ -338,7 +338,7 @@ void ArchMultithreadPosix::closeThread(ArchThread thread)
|
||||
|
||||
// remove thread from list
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
assert(findNoRef(thread->m_thread) == thread);
|
||||
erase(thread);
|
||||
}
|
||||
@ -362,7 +362,7 @@ void ArchMultithreadPosix::cancelThread(ArchThread thread)
|
||||
bool wakeup = false;
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
if (!thread->m_exited && !thread->m_cancelling) {
|
||||
thread->m_cancel = true;
|
||||
wakeup = true;
|
||||
@ -387,7 +387,7 @@ void ArchMultithreadPosix::testCancelThread()
|
||||
// find current thread
|
||||
ArchThreadImpl *thread = nullptr;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
thread = findNoRef(pthread_self());
|
||||
}
|
||||
// test cancel on thread
|
||||
@ -400,7 +400,7 @@ bool ArchMultithreadPosix::wait(ArchThread target, double timeout)
|
||||
|
||||
ArchThreadImpl *self = nullptr;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
// find current thread
|
||||
self = findNoRef(pthread_self());
|
||||
// ignore wait if trying to wait on ourself
|
||||
@ -452,13 +452,13 @@ bool ArchMultithreadPosix::isSameThread(ArchThread thread1, ArchThread thread2)
|
||||
|
||||
bool ArchMultithreadPosix::isExitedThread(ArchThread thread)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
return thread->m_exited;
|
||||
}
|
||||
|
||||
void *ArchMultithreadPosix::getResultOfThread(ArchThread thread)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
return thread->m_result;
|
||||
}
|
||||
|
||||
@ -469,14 +469,14 @@ IArchMultithread::ThreadID ArchMultithreadPosix::getIDOfThread(ArchThread thread
|
||||
|
||||
void ArchMultithreadPosix::setSignalHandler(ESignal signal, SignalFunc func, void *userData)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
m_signalFunc[signal] = func;
|
||||
m_signalUserData[signal] = userData;
|
||||
}
|
||||
|
||||
void ArchMultithreadPosix::raiseSignal(ESignal signal)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
if (m_signalFunc[signal] != nullptr) {
|
||||
m_signalFunc[signal](signal, m_signalUserData[signal]);
|
||||
pthread_kill(m_mainThread->m_thread, SIGWAKEUP);
|
||||
@ -570,7 +570,7 @@ void ArchMultithreadPosix::testCancelThreadImpl(ArchThreadImpl *thread)
|
||||
assert(thread != nullptr);
|
||||
|
||||
// update cancel state
|
||||
std::lock_guard<std::mutex> lock(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
bool cancel = false;
|
||||
if (thread->m_cancel && !thread->m_cancelling) {
|
||||
thread->m_cancelling = true;
|
||||
@ -607,7 +607,7 @@ void ArchMultithreadPosix::doThreadFunc(ArchThread thread)
|
||||
|
||||
// wait for parent to initialize this object
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
}
|
||||
|
||||
void *result = nullptr;
|
||||
@ -623,7 +623,7 @@ void ArchMultithreadPosix::doThreadFunc(ArchThread thread)
|
||||
} catch (...) {
|
||||
// note -- don't catch (...) to avoid masking bugs
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
thread->m_exited = true;
|
||||
}
|
||||
closeThread(thread);
|
||||
@ -632,7 +632,7 @@ void ArchMultithreadPosix::doThreadFunc(ArchThread thread)
|
||||
|
||||
// thread has exited
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
thread->m_result = result;
|
||||
thread->m_exited = true;
|
||||
}
|
||||
|
||||
@ -124,7 +124,7 @@ ArchSocket ArchNetworkBSD::copySocket(ArchSocket s)
|
||||
assert(s != nullptr);
|
||||
|
||||
// ref the socket and return it
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
++s->m_refCount;
|
||||
return s;
|
||||
}
|
||||
@ -136,7 +136,7 @@ void ArchNetworkBSD::closeSocket(ArchSocket s)
|
||||
bool doClose = false;
|
||||
// unref the socket and note if it should be released
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
doClose = (--s->m_refCount == 0);
|
||||
}
|
||||
|
||||
@ -146,7 +146,7 @@ void ArchNetworkBSD::closeSocket(ArchSocket s)
|
||||
// close failed. restore the last ref and throw.
|
||||
int err = errno;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
++s->m_refCount;
|
||||
}
|
||||
throwError(err);
|
||||
@ -531,7 +531,7 @@ std::vector<ArchNetAddress> ArchNetworkBSD::nameToAddr(const std::string &name)
|
||||
}
|
||||
|
||||
// done with static buffer
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
struct addrinfo *pResult = nullptr;
|
||||
|
||||
if (int ret = getaddrinfo(name.c_str(), nullptr, &hints, &pResult); ret != 0) {
|
||||
@ -568,7 +568,7 @@ std::string ArchNetworkBSD::addrToName(ArchNetAddress addr)
|
||||
assert(addr != nullptr);
|
||||
|
||||
// mutexed name lookup (ugh)
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
char host[1024];
|
||||
char service[20];
|
||||
|
||||
@ -591,7 +591,7 @@ std::string ArchNetworkBSD::addrToString(ArchNetAddress addr)
|
||||
switch (getAddrFamily(addr)) {
|
||||
case kINET: {
|
||||
const auto *ipAddr = TYPED_ADDR(struct sockaddr_in, addr);
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
std::string s = inet_ntoa(ipAddr->sin_addr);
|
||||
return s;
|
||||
}
|
||||
@ -600,7 +600,7 @@ std::string ArchNetworkBSD::addrToString(ArchNetAddress addr)
|
||||
char strAddr[INET6_ADDRSTRLEN];
|
||||
const auto *ipAddr = TYPED_ADDR(struct sockaddr_in6, addr);
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
inet_ntop(AF_INET6, &ipAddr->sin6_addr, strAddr, INET6_ADDRSTRLEN);
|
||||
}
|
||||
return strAddr;
|
||||
|
||||
@ -85,7 +85,7 @@ ArchMultithreadWindows::ArchMultithreadWindows()
|
||||
m_signalUserData[i] = nullptr;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
|
||||
// create thread for calling (main) thread and add it to our
|
||||
// list. no need to lock the mutex since we're the only thread.
|
||||
@ -107,20 +107,20 @@ ArchMultithreadWindows::~ArchMultithreadWindows()
|
||||
|
||||
void ArchMultithreadWindows::setNetworkDataForCurrentThread(void *data)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
ArchThreadImpl *thread = findNoRef(GetCurrentThreadId());
|
||||
thread->m_networkData = data;
|
||||
}
|
||||
|
||||
void *ArchMultithreadWindows::getNetworkDataForThread(ArchThread thread)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
return thread->m_networkData;
|
||||
}
|
||||
|
||||
HANDLE ArchMultithreadWindows::getCancelEventForCurrentThread()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
ArchThreadImpl *thread = findNoRef(GetCurrentThreadId());
|
||||
return thread->m_cancel;
|
||||
}
|
||||
@ -255,7 +255,7 @@ void ArchMultithreadWindows::unlockMutex(ArchMutex mutex)
|
||||
ArchThread ArchMultithreadWindows::newThread(ThreadFunc func, void *data)
|
||||
{
|
||||
// note that the child thread will wait until we release this mutex
|
||||
std::lock_guard<std::mutex> lock(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
|
||||
// create thread impl for new thread
|
||||
ArchThreadImpl *thread = new ArchThreadImpl;
|
||||
@ -285,7 +285,7 @@ ArchThread ArchMultithreadWindows::newThread(ThreadFunc func, void *data)
|
||||
|
||||
ArchThread ArchMultithreadWindows::newCurrentThread()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
ArchThreadImpl *thread = find(GetCurrentThreadId());
|
||||
assert(thread != nullptr);
|
||||
return thread;
|
||||
@ -304,7 +304,7 @@ void ArchMultithreadWindows::closeThread(ArchThread thread)
|
||||
|
||||
// remove thread from list
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
assert(findNoRefOrCreate(thread->m_id) == thread);
|
||||
erase(thread);
|
||||
}
|
||||
@ -389,7 +389,7 @@ void ArchMultithreadWindows::setPriorityOfThread(ArchThread thread, int n)
|
||||
void ArchMultithreadWindows::testCancelThread()
|
||||
{
|
||||
// find current thread
|
||||
std::lock_guard<std::mutex> lock(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
ArchThreadImpl *thread = findNoRef(GetCurrentThreadId());
|
||||
|
||||
// test cancel on thread
|
||||
@ -402,7 +402,7 @@ bool ArchMultithreadWindows::wait(ArchThread target, double timeout)
|
||||
|
||||
ArchThreadImpl *self = nullptr;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
// find current thread
|
||||
self = findNoRef(GetCurrentThreadId());
|
||||
// ignore wait if trying to wait on ourself
|
||||
@ -465,7 +465,7 @@ bool ArchMultithreadWindows::isExitedThread(ArchThread thread)
|
||||
|
||||
void *ArchMultithreadWindows::getResultOfThread(ArchThread thread)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
return thread->m_result;
|
||||
}
|
||||
|
||||
@ -476,14 +476,14 @@ IArchMultithread::ThreadID ArchMultithreadWindows::getIDOfThread(ArchThread thre
|
||||
|
||||
void ArchMultithreadWindows::setSignalHandler(ESignal signal, SignalFunc func, void *userData)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
m_signalFunc[signal] = func;
|
||||
m_signalUserData[signal] = userData;
|
||||
}
|
||||
|
||||
void ArchMultithreadWindows::raiseSignal(ESignal signal)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
if (m_signalFunc[signal] != nullptr) {
|
||||
m_signalFunc[signal](signal, m_signalUserData[signal]);
|
||||
ARCH->unblockPollSocket(m_mainThread);
|
||||
@ -567,7 +567,7 @@ void ArchMultithreadWindows::testCancelThreadImpl(ArchThreadImpl *thread)
|
||||
}
|
||||
|
||||
// update cancel state
|
||||
std::lock_guard<std::mutex> lock(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
bool cancel = !thread->m_cancelling;
|
||||
thread->m_cancelling = true;
|
||||
ResetEvent(thread->m_cancel);
|
||||
@ -594,7 +594,7 @@ void ArchMultithreadWindows::doThreadFunc(ArchThread thread)
|
||||
{
|
||||
// wait for parent to initialize this object
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
}
|
||||
|
||||
void *result = nullptr;
|
||||
@ -608,7 +608,7 @@ void ArchMultithreadWindows::doThreadFunc(ArchThread thread)
|
||||
} catch (...) {
|
||||
// note -- don't catch (...) to avoid masking bugs
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
SetEvent(thread->m_exit);
|
||||
}
|
||||
closeThread(thread);
|
||||
@ -617,7 +617,7 @@ void ArchMultithreadWindows::doThreadFunc(ArchThread thread)
|
||||
|
||||
// thread has exited
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
thread->m_result = result;
|
||||
SetEvent(thread->m_exit);
|
||||
}
|
||||
|
||||
@ -225,7 +225,7 @@ ArchSocket ArchNetworkWinsock::copySocket(ArchSocket s)
|
||||
assert(s != nullptr);
|
||||
|
||||
// ref the socket and return it
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
++s->m_refCount;
|
||||
return s;
|
||||
}
|
||||
@ -237,7 +237,7 @@ void ArchNetworkWinsock::closeSocket(ArchSocket s)
|
||||
// unref the socket and note if it should be released
|
||||
bool doClose = false;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
doClose = (--s->m_refCount == 0);
|
||||
}
|
||||
|
||||
@ -247,7 +247,7 @@ void ArchNetworkWinsock::closeSocket(ArchSocket s)
|
||||
// close failed. restore the last ref and throw.
|
||||
int err = getsockerror_winsock();
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
++s->m_refCount;
|
||||
}
|
||||
throwError(err);
|
||||
@ -684,7 +684,7 @@ std::vector<ArchNetAddress> ArchNetworkWinsock::nameToAddr(const std::string &na
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
int ret = -1;
|
||||
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
if ((ret = getaddrinfo(name.c_str(), nullptr, &hints, &pResult)) != 0) {
|
||||
throwNameError(ret);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -208,7 +208,7 @@ void Log::insert(ILogOutputter *adoptedOutputter, bool alwaysAtHead)
|
||||
{
|
||||
assert(adoptedOutputter != nullptr);
|
||||
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
if (alwaysAtHead) {
|
||||
m_alwaysOutputters.push_front(adoptedOutputter);
|
||||
} else {
|
||||
@ -220,14 +220,14 @@ void Log::insert(ILogOutputter *adoptedOutputter, bool alwaysAtHead)
|
||||
|
||||
void Log::remove(ILogOutputter *outputter)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
m_outputters.remove(outputter);
|
||||
m_alwaysOutputters.remove(outputter);
|
||||
}
|
||||
|
||||
void Log::pop_front(bool alwaysAtHead)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
OutputterList *list = alwaysAtHead ? &m_alwaysOutputters : &m_outputters;
|
||||
if (!list->empty()) {
|
||||
delete list->front();
|
||||
@ -251,13 +251,13 @@ bool Log::setFilter(const char *maxPriority)
|
||||
|
||||
void Log::setFilter(int maxPriority)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
m_maxPriority = maxPriority;
|
||||
}
|
||||
|
||||
int Log::getFilter() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
return m_maxPriority;
|
||||
}
|
||||
|
||||
@ -268,7 +268,7 @@ void Log::output(ELevel priority, const char *msg)
|
||||
if (!msg)
|
||||
return;
|
||||
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
|
||||
OutputterList::const_iterator i;
|
||||
|
||||
|
||||
@ -26,7 +26,7 @@ PacketStreamFilter::PacketStreamFilter(IEventQueue *events, deskflow::IStream *s
|
||||
|
||||
void PacketStreamFilter::close()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
m_size = 0;
|
||||
m_buffer.pop(m_buffer.getSize());
|
||||
StreamFilter::close();
|
||||
@ -38,7 +38,7 @@ uint32_t PacketStreamFilter::read(void *buffer, uint32_t n)
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
|
||||
// if not enough data yet then give up
|
||||
if (!isReadyNoLock()) {
|
||||
@ -84,7 +84,7 @@ void PacketStreamFilter::write(const void *buffer, uint32_t count)
|
||||
|
||||
void PacketStreamFilter::shutdownInput()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
m_size = 0;
|
||||
m_buffer.pop(m_buffer.getSize());
|
||||
StreamFilter::shutdownInput();
|
||||
@ -92,13 +92,13 @@ void PacketStreamFilter::shutdownInput()
|
||||
|
||||
bool PacketStreamFilter::isReady() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
return isReadyNoLock();
|
||||
}
|
||||
|
||||
uint32_t PacketStreamFilter::getSize() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
return isReadyNoLock() ? m_size : 0;
|
||||
}
|
||||
|
||||
@ -157,13 +157,13 @@ bool PacketStreamFilter::readMore()
|
||||
void PacketStreamFilter::filterEvent(const Event &event)
|
||||
{
|
||||
if (event.getType() == EventTypes::StreamInputReady) {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
if (!readMore()) {
|
||||
return;
|
||||
}
|
||||
} else if (event.getType() == EventTypes::StreamInputShutdown) {
|
||||
// discard this if we have buffered data
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
m_inputShutdown = true;
|
||||
if (m_size != 0) {
|
||||
return;
|
||||
|
||||
@ -197,7 +197,7 @@ void AppUtilWindows::eventLoop()
|
||||
|
||||
LOG_DEBUG("windows event loop running");
|
||||
{
|
||||
std::lock_guard lock(m_eventThreadStartedMutex);
|
||||
std::scoped_lock lock{m_eventThreadStartedMutex};
|
||||
m_eventThreadRunning = true;
|
||||
}
|
||||
m_eventThreadStartedCond.notify_one();
|
||||
|
||||
@ -230,7 +230,7 @@ TCPSocket::EJobResult SecureSocket::doWrite()
|
||||
|
||||
int SecureSocket::secureRead(void *buffer, int size, int &read)
|
||||
{
|
||||
std::lock_guard ssl_lock{ssl_mutex_};
|
||||
std::scoped_lock ssl_lock{ssl_mutex_};
|
||||
|
||||
if (m_ssl->m_ssl != nullptr) {
|
||||
LOG((CLOG_DEBUG2 "reading secure socket"));
|
||||
@ -257,7 +257,7 @@ int SecureSocket::secureRead(void *buffer, int size, int &read)
|
||||
|
||||
int SecureSocket::secureWrite(const void *buffer, int size, int &wrote)
|
||||
{
|
||||
std::lock_guard ssl_lock{ssl_mutex_};
|
||||
std::scoped_lock ssl_lock{ssl_mutex_};
|
||||
|
||||
if (m_ssl->m_ssl != nullptr) {
|
||||
LOG((CLOG_DEBUG2 "writing secure socket: %p", this));
|
||||
@ -290,7 +290,7 @@ bool SecureSocket::isSecureReady() const
|
||||
|
||||
void SecureSocket::initSsl(bool server)
|
||||
{
|
||||
std::lock_guard ssl_lock{ssl_mutex_};
|
||||
std::scoped_lock ssl_lock{ssl_mutex_};
|
||||
|
||||
m_ssl = new Ssl();
|
||||
m_ssl->m_context = nullptr;
|
||||
@ -301,7 +301,7 @@ void SecureSocket::initSsl(bool server)
|
||||
|
||||
bool SecureSocket::loadCertificates(const std::string &filename)
|
||||
{
|
||||
std::lock_guard ssl_lock{ssl_mutex_};
|
||||
std::scoped_lock ssl_lock{ssl_mutex_};
|
||||
|
||||
if (filename.empty()) {
|
||||
SslLogger::logError("tls certificate is not specified");
|
||||
@ -392,7 +392,7 @@ void SecureSocket::createSSL()
|
||||
|
||||
void SecureSocket::freeSSL()
|
||||
{
|
||||
std::lock_guard ssl_lock{ssl_mutex_};
|
||||
std::scoped_lock ssl_lock{ssl_mutex_};
|
||||
|
||||
isFatal(true);
|
||||
// take socket from multiplexer ASAP otherwise the race condition
|
||||
@ -417,7 +417,7 @@ void SecureSocket::freeSSL()
|
||||
|
||||
int SecureSocket::secureAccept(int socket)
|
||||
{
|
||||
std::lock_guard ssl_lock{ssl_mutex_};
|
||||
std::scoped_lock ssl_lock{ssl_mutex_};
|
||||
|
||||
createSSL();
|
||||
|
||||
@ -479,7 +479,7 @@ int SecureSocket::secureConnect(int socket)
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::lock_guard ssl_lock{ssl_mutex_};
|
||||
std::scoped_lock ssl_lock{ssl_mutex_};
|
||||
|
||||
createSSL();
|
||||
|
||||
|
||||
@ -51,7 +51,7 @@ TCPListenSocket::~TCPListenSocket()
|
||||
void TCPListenSocket::bind(const NetworkAddress &addr)
|
||||
{
|
||||
try {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
ARCH->setReuseAddrOnSocket(m_socket, true);
|
||||
ARCH->bindSocket(m_socket, addr.getAddress());
|
||||
ARCH->listenOnSocket(m_socket);
|
||||
@ -69,7 +69,7 @@ void TCPListenSocket::bind(const NetworkAddress &addr)
|
||||
|
||||
void TCPListenSocket::close()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
if (m_socket == nullptr) {
|
||||
throw XIOClosed();
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ void EiEventQueueBuffer::waitForEvent(double timeout_in_ms)
|
||||
|
||||
if (int retval = poll(pfds, POLLFD_COUNT, timeout); retval > 0) {
|
||||
if (pfds[EIFD].revents & POLLIN) {
|
||||
std::lock_guard lock(mutex_);
|
||||
std::scoped_lock lock{mutex_};
|
||||
|
||||
// libei doesn't allow ei_event_ref() because events are
|
||||
// supposed to be short-lived only. So instead, we create an nullptr-data
|
||||
@ -108,7 +108,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 lock(mutex_);
|
||||
std::scoped_lock lock{mutex_};
|
||||
auto pair = queue_.front();
|
||||
queue_.pop();
|
||||
|
||||
@ -125,7 +125,7 @@ IEventQueueBuffer::Type EiEventQueueBuffer::getEvent(Event &event, uint32_t &dat
|
||||
|
||||
bool EiEventQueueBuffer::addEvent(uint32_t dataID)
|
||||
{
|
||||
std::lock_guard lock(mutex_);
|
||||
std::scoped_lock lock{mutex_};
|
||||
queue_.push({false, dataID});
|
||||
|
||||
// tickle the pipe so our read thread wakes up
|
||||
@ -137,7 +137,7 @@ bool EiEventQueueBuffer::addEvent(uint32_t dataID)
|
||||
|
||||
bool EiEventQueueBuffer::isEmpty() const
|
||||
{
|
||||
std::lock_guard lock(mutex_);
|
||||
std::scoped_lock lock{mutex_};
|
||||
|
||||
return queue_.empty();
|
||||
}
|
||||
|
||||
@ -720,7 +720,7 @@ void EiScreen::handle_portal_session_closed(const Event &event, void *)
|
||||
|
||||
void EiScreen::handleSystemEvent(const Event &sysevent, void *)
|
||||
{
|
||||
std::lock_guard lock(mutex_);
|
||||
std::scoped_lock lock{mutex_};
|
||||
|
||||
// Only one ei_dispatch per system event, see the comment in
|
||||
// EiEventQueueBuffer::addEvent
|
||||
|
||||
@ -327,7 +327,7 @@ void MSWindowsWatchdog::startProcess()
|
||||
void MSWindowsWatchdog::setProcessConfig(const std::string_view &command, bool elevate)
|
||||
{
|
||||
LOG_DEBUG1("locking process state mutex for watchdog config change");
|
||||
std::lock_guard lock(m_processStateMutex);
|
||||
std::scoped_lock lock{m_processStateMutex};
|
||||
|
||||
LOG_DEBUG("setting watchdog process config");
|
||||
m_command = command;
|
||||
|
||||
@ -66,7 +66,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 lock(this->m_mutex);
|
||||
std::scoped_lock lock{this->m_mutex};
|
||||
LOG_DEBUG2("adding user event with dataID: %u", dataID);
|
||||
this->m_dataQueue.push(dataID);
|
||||
this->m_cond.notify_one();
|
||||
@ -79,7 +79,7 @@ bool OSXEventQueueBuffer::addEvent(uint32_t dataID)
|
||||
|
||||
bool OSXEventQueueBuffer::isEmpty() const
|
||||
{
|
||||
std::lock_guard lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
bool empty = m_dataQueue.empty();
|
||||
LOG_DEBUG2("queue is %s", empty ? "empty" : "not empty");
|
||||
return empty;
|
||||
|
||||
@ -50,7 +50,7 @@ XWindowsEventQueueBuffer::~XWindowsEventQueueBuffer()
|
||||
|
||||
int XWindowsEventQueueBuffer::getPendingCountLocked()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
return XPending(m_display);
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ void XWindowsEventQueueBuffer::waitForEvent(double dtimeout)
|
||||
}
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
// we're now waiting for events
|
||||
m_waiting = true;
|
||||
|
||||
@ -122,7 +122,7 @@ void XWindowsEventQueueBuffer::waitForEvent(double dtimeout)
|
||||
|
||||
{
|
||||
// we're no longer waiting for events
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
m_waiting = false;
|
||||
}
|
||||
|
||||
@ -131,7 +131,7 @@ void XWindowsEventQueueBuffer::waitForEvent(double dtimeout)
|
||||
|
||||
IEventQueueBuffer::Type XWindowsEventQueueBuffer::getEvent(Event &event, uint32_t &dataID)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
|
||||
// push out pending events
|
||||
flush();
|
||||
@ -160,7 +160,7 @@ bool XWindowsEventQueueBuffer::addEvent(uint32_t dataID)
|
||||
xevent.xclient.data.l[0] = static_cast<long>(dataID);
|
||||
|
||||
// save the message
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
m_postedEvents.push_back(xevent);
|
||||
|
||||
// if we're currently waiting for an event then send saved events to
|
||||
@ -186,7 +186,7 @@ bool XWindowsEventQueueBuffer::addEvent(uint32_t dataID)
|
||||
|
||||
bool XWindowsEventQueueBuffer::isEmpty() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
return (XPending(m_display) == 0);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user