diff --git a/app/src/main/cpp/skyline/audio.cpp b/app/src/main/cpp/skyline/audio.cpp index c559f421..6b1ab0de 100644 --- a/app/src/main/cpp/skyline/audio.cpp +++ b/app/src/main/cpp/skyline/audio.cpp @@ -23,7 +23,7 @@ namespace skyline::audio { } std::shared_ptr Audio::OpenTrack(u8 channelCount, u32 sampleRate, const std::function &releaseCallback) { - std::lock_guard trackGuard(trackLock); + std::scoped_lock trackGuard{trackLock}; auto track{std::make_shared(channelCount, sampleRate, releaseCallback)}; audioTracks.push_back(track); @@ -32,7 +32,7 @@ namespace skyline::audio { } void Audio::CloseTrack(std::shared_ptr &track) { - std::lock_guard trackGuard(trackLock); + std::scoped_lock trackGuard{trackLock}; audioTracks.erase(std::remove(audioTracks.begin(), audioTracks.end(), track), audioTracks.end()); } @@ -43,13 +43,13 @@ namespace skyline::audio { size_t writtenSamples{}; { - std::lock_guard trackGuard(trackLock); + std::scoped_lock trackGuard{trackLock}; for (auto &track : audioTracks) { if (track->playbackState == AudioOutState::Stopped) continue; - std::lock_guard bufferGuard(track->bufferLock); + std::scoped_lock bufferGuard{track->bufferLock}; auto trackSamples{track->samples.Read(span(destBuffer, streamSamples), [](i16 *source, i16 *destination) { *destination = Saturate(static_cast(*destination) + static_cast(*source)); diff --git a/app/src/main/cpp/skyline/common/circular_buffer.h b/app/src/main/cpp/skyline/common/circular_buffer.h index c3b13cee..0ddfcc8a 100644 --- a/app/src/main/cpp/skyline/common/circular_buffer.h +++ b/app/src/main/cpp/skyline/common/circular_buffer.h @@ -29,7 +29,7 @@ namespace skyline { * @return The amount of data written into the input buffer in units of Type */ size_t Read(span buffer, void copyFunction(Type *, Type *) = {}, ssize_t copyOffset = -1) { - std::lock_guard guard(mtx); + std::scoped_lock guard{mtx}; if (empty) return 0; @@ -92,7 +92,7 @@ namespace skyline { * @brief Appends data from the specified buffer into this buffer */ void Append(span buffer) { - std::lock_guard guard(mtx); + std::scoped_lock guard{mtx}; Type *pointer{buffer.data()}; ssize_t size{static_cast(buffer.size())}; diff --git a/app/src/main/cpp/skyline/common/logger.cpp b/app/src/main/cpp/skyline/common/logger.cpp index 5bf969dd..8f7c7840 100644 --- a/app/src/main/cpp/skyline/common/logger.cpp +++ b/app/src/main/cpp/skyline/common/logger.cpp @@ -12,7 +12,7 @@ namespace skyline { } void Logger::LoggerContext::Finalize() { - std::lock_guard lock(mutex); + std::scoped_lock lock{mutex}; logFile.close(); } @@ -23,7 +23,7 @@ namespace skyline { } void Logger::LoggerContext::Flush() { - std::lock_guard lock(mutex); + std::scoped_lock lock{mutex}; logFile.flush(); } @@ -65,7 +65,7 @@ namespace skyline { } void Logger::LoggerContext::Write(const std::string &str) { - std::lock_guard guard(mutex); + std::scoped_lock guard{mutex}; logFile << str; } } diff --git a/app/src/main/cpp/skyline/gpu/buffer.cpp b/app/src/main/cpp/skyline/gpu/buffer.cpp index 5659ada2..82a20e05 100644 --- a/app/src/main/cpp/skyline/gpu/buffer.cpp +++ b/app/src/main/cpp/skyline/gpu/buffer.cpp @@ -21,11 +21,11 @@ namespace skyline::gpu { mirror = alignedMirror.subspan(static_cast(guest->data() - alignedData), guest->size()); trapHandle = gpu.state.nce->TrapRegions(*guest, true, [this] { - std::lock_guard lock(*this); + std::scoped_lock lock{*this}; SynchronizeGuest(true); // We can skip trapping since the caller will do it WaitOnFence(); }, [this] { - std::lock_guard lock(*this); + std::scoped_lock lock{*this}; SynchronizeGuest(true); dirtyState = DirtyState::CpuDirty; // We need to assume the buffer is dirty since we don't know what the guest is writing WaitOnFence(); @@ -95,7 +95,7 @@ namespace skyline::gpu { } Buffer::~Buffer() { - std::lock_guard lock(*this); + std::scoped_lock lock{*this}; if (trapHandle) gpu.state.nce->DeleteTrap(*trapHandle); SynchronizeGuest(true); diff --git a/app/src/main/cpp/skyline/gpu/interconnect/graphics_context.h b/app/src/main/cpp/skyline/gpu/interconnect/graphics_context.h index c6832df9..3d6e0d50 100644 --- a/app/src/main/cpp/skyline/gpu/interconnect/graphics_context.h +++ b/app/src/main/cpp/skyline/gpu/interconnect/graphics_context.h @@ -514,7 +514,7 @@ namespace skyline::gpu::interconnect { } void ClearColorRt(TextureView *renderTarget, vk::Rect2D scissor, u32 layerIndex) { - std::lock_guard lock(*renderTarget); + std::scoped_lock lock{*renderTarget}; executor.AttachTexture(renderTarget); scissor.extent.width = static_cast(std::min(static_cast(renderTarget->texture->dimensions.width) - scissor.offset.x, @@ -546,7 +546,7 @@ namespace skyline::gpu::interconnect { } void ClearDepthStencilRt(TextureView *renderTarget, vk::ImageAspectFlags aspect, u32 layerIndex) { - std::lock_guard lock(*renderTarget); + std::scoped_lock lock{*renderTarget}; executor.AttachTexture(renderTarget); if (renderTarget->range.layerCount == 1 && layerIndex == 0) { diff --git a/app/src/main/cpp/skyline/gpu/presentation_engine.cpp b/app/src/main/cpp/skyline/gpu/presentation_engine.cpp index 233f1716..c705991f 100644 --- a/app/src/main/cpp/skyline/gpu/presentation_engine.cpp +++ b/app/src/main/cpp/skyline/gpu/presentation_engine.cpp @@ -172,7 +172,7 @@ namespace skyline::gpu { } void PresentationEngine::UpdateSurface(jobject newSurface) { - std::lock_guard guard(mutex); + std::scoped_lock guard{mutex}; auto env{state.jvm->GetEnv()}; if (!env->IsSameObject(jSurface, nullptr)) { @@ -295,7 +295,7 @@ namespace skyline::gpu { throw exception("Retrieving the next frame's ID failed with {}", result); { - std::lock_guard queueLock(gpu.queueMutex); + std::scoped_lock queueLock{gpu.queueMutex}; std::ignore = gpu.vkQueue.presentKHR(vk::PresentInfoKHR{ .swapchainCount = 1, .pSwapchains = &**vkSwapchain, diff --git a/app/src/main/cpp/skyline/gpu/texture/texture.cpp b/app/src/main/cpp/skyline/gpu/texture/texture.cpp index 373b7ee1..ad9a7867 100644 --- a/app/src/main/cpp/skyline/gpu/texture/texture.cpp +++ b/app/src/main/cpp/skyline/gpu/texture/texture.cpp @@ -106,11 +106,11 @@ namespace skyline::gpu { } trapHandle = gpu.state.nce->TrapRegions(mappings, true, [this] { - std::lock_guard lock(*this); + std::scoped_lock lock{*this}; SynchronizeGuest(true); // We can skip trapping since the caller will do it WaitOnFence(); }, [this] { - std::lock_guard lock(*this); + std::scoped_lock lock{*this}; SynchronizeGuest(true); dirtyState = DirtyState::CpuDirty; // We need to assume the texture is dirty since we don't know what the guest is writing WaitOnFence(); @@ -339,7 +339,7 @@ namespace skyline::gpu { } Texture::~Texture() { - std::lock_guard lock(*this); + std::scoped_lock lock{*this}; if (trapHandle) gpu.state.nce->DeleteTrap(*trapHandle); SynchronizeGuest(true); diff --git a/app/src/main/cpp/skyline/input/npad.cpp b/app/src/main/cpp/skyline/input/npad.cpp index 00dcefeb..e1bfadbc 100644 --- a/app/src/main/cpp/skyline/input/npad.cpp +++ b/app/src/main/cpp/skyline/input/npad.cpp @@ -14,7 +14,7 @@ namespace skyline::input { } { Activate(); /* NPads are activated by default, certain homebrew is reliant on this behavior */ } void NpadManager::Update() { - std::lock_guard guard(mutex); + std::scoped_lock guard{mutex}; if (!activated) return; @@ -75,7 +75,7 @@ namespace skyline::input { } void NpadManager::Activate() { - std::lock_guard guard(mutex); + std::scoped_lock guard{mutex}; if (!activated) { supportedIds = {NpadId::Handheld, NpadId::Player1, NpadId::Player2, NpadId::Player3, NpadId::Player4, NpadId::Player5, NpadId::Player6, NpadId::Player7, NpadId::Player8}; styles = {.proController = true, .joyconHandheld = true, .joyconDual = true, .joyconLeft = true, .joyconRight = true}; @@ -86,7 +86,7 @@ namespace skyline::input { } void NpadManager::Deactivate() { - std::lock_guard guard(mutex); + std::scoped_lock guard{mutex}; if (activated) { supportedIds = {}; styles = {}; diff --git a/app/src/main/cpp/skyline/kernel/scheduler.cpp b/app/src/main/cpp/skyline/kernel/scheduler.cpp index d3652cb7..8697fafb 100644 --- a/app/src/main/cpp/skyline/kernel/scheduler.cpp +++ b/app/src/main/cpp/skyline/kernel/scheduler.cpp @@ -40,7 +40,7 @@ namespace skyline::kernel { u64 timeslice{}; if (!candidateCore.queue.empty()) { - std::lock_guard coreLock(candidateCore.mutex); + std::scoped_lock coreLock{candidateCore.mutex}; auto threadIterator{candidateCore.queue.cbegin()}; if (threadIterator != candidateCore.queue.cend()) { @@ -155,7 +155,7 @@ namespace skyline::kernel { auto wakeFunction{[&]() { if (!thread->affinityMask.test(thread->coreId)) [[unlikely]] { lock.unlock(); // If the core migration mutex is locked by a thread seeking the core mutex, it'll result in a deadlock - std::lock_guard migrationLock(thread->coreMigrationMutex); + std::scoped_lock migrationLock{thread->coreMigrationMutex}; lock.lock(); if (!thread->affinityMask.test(thread->coreId)) // We need to retest in case the thread was migrated while the core was unlocked MigrateToCore(thread, core, &cores.at(thread->idealCore), lock); @@ -168,7 +168,7 @@ namespace skyline::kernel { std::chrono::milliseconds loadBalanceThreshold{PreemptiveTimeslice * 2}; //!< The amount of time that needs to pass unscheduled for a thread to attempt load balancing while (!thread->scheduleCondition.wait_for(lock, loadBalanceThreshold, wakeFunction)) { lock.unlock(); // We cannot call GetOptimalCoreForThread without relinquishing the core mutex - std::lock_guard migrationLock(thread->coreMigrationMutex); + std::scoped_lock migrationLock{thread->coreMigrationMutex}; auto newCore{&GetOptimalCoreForThread(state.thread)}; lock.lock(); if (core != newCore) @@ -195,7 +195,7 @@ namespace skyline::kernel { std::unique_lock lock(core->mutex); if (thread->scheduleCondition.wait_for(lock, timeout, [&]() { if (!thread->affinityMask.test(thread->coreId)) [[unlikely]] { - std::lock_guard migrationLock(thread->coreMigrationMutex); + std::scoped_lock migrationLock{thread->coreMigrationMutex}; MigrateToCore(thread, core, &cores.at(thread->idealCore), lock); } return !core->queue.empty() && core->queue.front() == thread; @@ -263,7 +263,7 @@ namespace skyline::kernel { } void Scheduler::UpdatePriority(const std::shared_ptr &thread) { - std::lock_guard migrationLock(thread->coreMigrationMutex); + std::scoped_lock migrationLock{thread->coreMigrationMutex}; auto *core{&cores.at(thread->coreId)}; std::unique_lock coreLock(core->mutex); @@ -304,7 +304,7 @@ namespace skyline::kernel { void Scheduler::UpdateCore(const std::shared_ptr &thread) { auto *core{&cores.at(thread->coreId)}; - std::lock_guard coreLock(core->mutex); + std::scoped_lock coreLock{core->mutex}; if (core->queue.front() == thread) thread->SendSignal(YieldSignal); else @@ -313,7 +313,7 @@ namespace skyline::kernel { void Scheduler::ParkThread() { auto &thread{state.thread}; - std::lock_guard migrationLock(thread->coreMigrationMutex); + std::scoped_lock migrationLock{thread->coreMigrationMutex}; RemoveThread(); auto originalCoreId{thread->coreId}; diff --git a/app/src/main/cpp/skyline/kernel/svc.cpp b/app/src/main/cpp/skyline/kernel/svc.cpp index 21ab07f7..15182800 100644 --- a/app/src/main/cpp/skyline/kernel/svc.cpp +++ b/app/src/main/cpp/skyline/kernel/svc.cpp @@ -424,7 +424,7 @@ namespace skyline::kernel::svc { Logger::Debug("Setting thread #{}'s Ideal Core ({}) + Affinity Mask ({})", thread->id, idealCore, affinityMask); - std::lock_guard guard(thread->coreMigrationMutex); + std::scoped_lock guard{thread->coreMigrationMutex}; thread->idealCore = static_cast(idealCore); thread->affinityMask = affinityMask; @@ -451,7 +451,7 @@ namespace skyline::kernel::svc { } void GetCurrentProcessorNumber(const DeviceState &state) { - std::lock_guard guard(state.thread->coreMigrationMutex); + std::scoped_lock guard{state.thread->coreMigrationMutex}; u8 coreId{state.thread->coreId}; Logger::Debug("C{}", coreId); state.ctx->gpr.w0 = coreId; diff --git a/app/src/main/cpp/skyline/kernel/types/KProcess.cpp b/app/src/main/cpp/skyline/kernel/types/KProcess.cpp index ca31a00d..88f2a33c 100644 --- a/app/src/main/cpp/skyline/kernel/types/KProcess.cpp +++ b/app/src/main/cpp/skyline/kernel/types/KProcess.cpp @@ -19,7 +19,7 @@ namespace skyline::kernel::type { KProcess::KProcess(const DeviceState &state) : memory(state), KSyncObject(state, KType::KProcess) {} KProcess::~KProcess() { - std::lock_guard guard(threadMutex); + std::scoped_lock guard{threadMutex}; disableThreadCreation = true; for (const auto &thread : threads) thread->Kill(true); @@ -33,7 +33,7 @@ namespace skyline::kernel::type { else alreadyKilled.store(true); - std::lock_guard guard(threadMutex); + std::scoped_lock guard{threadMutex}; if (disableCreation) disableThreadCreation = true; if (all) { @@ -52,7 +52,7 @@ namespace skyline::kernel::type { } u8 *KProcess::AllocateTlsSlot() { - std::lock_guard lock(tlsMutex); + std::scoped_lock lock{tlsMutex}; u8 *slot; for (auto &tlsPage: tlsPages) if ((slot = tlsPage->ReserveSlot())) @@ -65,7 +65,7 @@ namespace skyline::kernel::type { } std::shared_ptr KProcess::CreateThread(void *entry, u64 argument, void *stackTop, std::optional priority, std::optional idealCore) { - std::lock_guard guard(threadMutex); + std::scoped_lock guard{threadMutex}; if (disableThreadCreation) return nullptr; if (!stackTop && threads.empty()) { //!< Main thread stack is created by the kernel and owned by the process @@ -122,7 +122,7 @@ namespace skyline::kernel::type { bool isHighestPriority; { - std::lock_guard lock(owner->waiterMutex); + std::scoped_lock lock{owner->waiterMutex}; u32 value{}; if (__atomic_compare_exchange_n(mutex, &value, tag, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) @@ -153,12 +153,12 @@ namespace skyline::kernel::type { void KProcess::MutexUnlock(u32 *mutex) { TRACE_EVENT_FMT("kernel", "MutexUnlock 0x{:X}", mutex); - std::lock_guard lock(state.thread->waiterMutex); + std::scoped_lock lock{state.thread->waiterMutex}; auto &waiters{state.thread->waiters}; auto nextOwnerIt{std::find_if(waiters.begin(), waiters.end(), [mutex](const std::shared_ptr &thread) { return thread->waitKey == mutex; })}; if (nextOwnerIt != waiters.end()) { auto nextOwner{*nextOwnerIt}; - std::lock_guard nextLock(nextOwner->waiterMutex); + std::scoped_lock nextLock{nextOwner->waiterMutex}; nextOwner->waitThread = std::shared_ptr{nullptr}; nextOwner->waitKey = nullptr; @@ -217,7 +217,7 @@ namespace skyline::kernel::type { TRACE_EVENT_FMT("kernel", "ConditionalVariableWait 0x{:X} (0x{:X})", key, mutex); { - std::lock_guard lock(syncWaiterMutex); + std::scoped_lock lock{syncWaiterMutex}; auto queue{syncWaiters.equal_range(key)}; syncWaiters.insert(std::upper_bound(queue.first, queue.second, state.thread->priority.load(), [](const i8 priority, const SyncWaiters::value_type &it) { return it.second->priority > priority; }), {key, state.thread}); @@ -257,7 +257,7 @@ namespace skyline::kernel::type { void KProcess::ConditionalVariableSignal(u32 *key, i32 amount) { TRACE_EVENT_FMT("kernel", "ConditionalVariableSignal 0x{:X}", key); - std::lock_guard lock(syncWaiterMutex); + std::scoped_lock lock{syncWaiterMutex}; auto queue{syncWaiters.equal_range(key)}; auto it{queue.first}; @@ -272,7 +272,7 @@ namespace skyline::kernel::type { TRACE_EVENT_FMT("kernel", "WaitForAddress 0x{:X}", address); { - std::lock_guard lock(syncWaiterMutex); + std::scoped_lock lock{syncWaiterMutex}; if (!arbitrationFunction(address, value)) [[unlikely]] return result::InvalidState; @@ -284,7 +284,7 @@ namespace skyline::kernel::type { if (timeout > 0 && !state.scheduler->TimedWaitSchedule(std::chrono::nanoseconds(timeout))) { { - std::lock_guard lock(syncWaiterMutex); + std::scoped_lock lock{syncWaiterMutex}; auto queue{syncWaiters.equal_range(address)}; auto iterator{std::find(queue.first, queue.second, SyncWaiters::value_type{address, state.thread})}; if (iterator != queue.second) @@ -306,7 +306,7 @@ namespace skyline::kernel::type { Result KProcess::SignalToAddress(u32 *address, u32 value, i32 amount, bool(*mutateFunction)(u32 *address, u32 value, u32 waiterCount)) { TRACE_EVENT_FMT("kernel", "SignalToAddress 0x{:X}", address); - std::lock_guard lock(syncWaiterMutex); + std::scoped_lock lock{syncWaiterMutex}; auto queue{syncWaiters.equal_range(address)}; if (mutateFunction) diff --git a/app/src/main/cpp/skyline/kernel/types/KSyncObject.cpp b/app/src/main/cpp/skyline/kernel/types/KSyncObject.cpp index 5e084a88..e89ab450 100644 --- a/app/src/main/cpp/skyline/kernel/types/KSyncObject.cpp +++ b/app/src/main/cpp/skyline/kernel/types/KSyncObject.cpp @@ -6,7 +6,7 @@ namespace skyline::kernel::type { void KSyncObject::Signal() { - std::lock_guard lock(syncObjectMutex); + std::scoped_lock lock{syncObjectMutex}; signalled = true; for (auto &waiter : syncObjectWaiters) { if (waiter->isCancellable) { @@ -18,7 +18,7 @@ namespace skyline::kernel::type { } bool KSyncObject::ResetSignal() { - std::lock_guard lock(syncObjectMutex); + std::scoped_lock lock{syncObjectMutex}; if (signalled) [[likely]] { signalled = false; return true; diff --git a/app/src/main/cpp/skyline/kernel/types/KThread.cpp b/app/src/main/cpp/skyline/kernel/types/KThread.cpp index 86cf1aad..8cb39ade 100644 --- a/app/src/main/cpp/skyline/kernel/types/KThread.cpp +++ b/app/src/main/cpp/skyline/kernel/types/KThread.cpp @@ -51,7 +51,7 @@ namespace skyline::kernel::type { state.scheduler->RemoveThread(); { - std::lock_guard lock(statusMutex); + std::scoped_lock lock{statusMutex}; running = false; ready = false; statusCondition.notify_all(); @@ -79,7 +79,7 @@ namespace skyline::kernel::type { signal::SetSignalHandler({Scheduler::YieldSignal, Scheduler::PreemptionSignal}, Scheduler::SignalHandler, false); // We want futexes to fail and their predicates rechecked { - std::lock_guard lock(statusMutex); + std::scoped_lock lock{statusMutex}; ready = true; statusCondition.notify_all(); } @@ -202,7 +202,7 @@ namespace skyline::kernel::type { std::unique_lock lock(statusMutex); if (!running) { { - std::lock_guard migrationLock(coreMigrationMutex); + std::scoped_lock migrationLock{coreMigrationMutex}; auto thisShared{shared_from_this()}; coreId = state.scheduler->GetOptimalCoreForThread(thisShared).id; state.scheduler->InsertThread(thisShared); @@ -283,11 +283,11 @@ namespace skyline::kernel::type { } while (waitingOn->priority.compare_exchange_strong(ownerPriority, currentPriority)); if (ownerPriority != currentPriority) { - std::lock_guard waiterLock(waitingOn->waiterMutex); + std::scoped_lock waiterLock{waitingOn->waiterMutex}; auto nextThread{waitingOn->waitThread}; if (nextThread) { // We need to update the location of the owner thread in the waiter queue of the thread it's waiting on - std::lock_guard nextWaiterLock(nextThread->waiterMutex); + std::scoped_lock nextWaiterLock{nextThread->waiterMutex}; auto &piWaiters{nextThread->waiters}; piWaiters.erase(std::find(piWaiters.begin(), piWaiters.end(), waitingOn)); piWaiters.insert(std::upper_bound(piWaiters.begin(), piWaiters.end(), currentPriority, KThread::IsHigherPriority), waitingOn); diff --git a/app/src/main/cpp/skyline/services/hid/IHidServer.cpp b/app/src/main/cpp/skyline/services/hid/IHidServer.cpp index 3a17c632..2f7362b4 100644 --- a/app/src/main/cpp/skyline/services/hid/IHidServer.cpp +++ b/app/src/main/cpp/skyline/services/hid/IHidServer.cpp @@ -31,7 +31,7 @@ namespace skyline::service::hid { Result IHidServer::SetSupportedNpadStyleSet(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { auto styleSet{request.Pop()}; - std::lock_guard lock(state.input->npad.mutex); + std::scoped_lock lock{state.input->npad.mutex}; state.input->npad.styles = styleSet; state.input->npad.Update(); @@ -47,7 +47,7 @@ namespace skyline::service::hid { Result IHidServer::SetSupportedNpadIdType(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { auto supportedIds{request.inputBuf.at(0).cast()}; - std::lock_guard lock(state.input->npad.mutex); + std::scoped_lock lock{state.input->npad.mutex}; state.input->npad.supportedIds.assign(supportedIds.begin(), supportedIds.end()); state.input->npad.Update(); return {}; @@ -105,7 +105,7 @@ namespace skyline::service::hid { } Result IHidServer::SetNpadJoyHoldType(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { - std::lock_guard lock(state.input->npad.mutex); + std::scoped_lock lock{state.input->npad.mutex}; request.Skip(); state.input->npad.orientation = request.Pop(); state.input->npad.Update(); @@ -119,7 +119,7 @@ namespace skyline::service::hid { Result IHidServer::SetNpadJoyAssignmentModeSingleByDefault(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { auto id{request.Pop()}; - std::lock_guard lock(state.input->npad.mutex); + std::scoped_lock lock{state.input->npad.mutex}; state.input->npad.at(id).SetAssignment(NpadJoyAssignment::Single); state.input->npad.Update(); return {}; @@ -127,7 +127,7 @@ namespace skyline::service::hid { Result IHidServer::SetNpadJoyAssignmentModeSingle(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { auto id{request.Pop()}; - std::lock_guard lock(state.input->npad.mutex); + std::scoped_lock lock{state.input->npad.mutex}; state.input->npad.at(id).SetAssignment(NpadJoyAssignment::Single); state.input->npad.Update(); return {}; @@ -135,7 +135,7 @@ namespace skyline::service::hid { Result IHidServer::SetNpadJoyAssignmentModeDual(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { auto id{request.Pop()}; - std::lock_guard lock(state.input->npad.mutex); + std::scoped_lock lock{state.input->npad.mutex}; state.input->npad.at(id).SetAssignment(NpadJoyAssignment::Dual); state.input->npad.Update(); return {}; diff --git a/app/src/main/cpp/skyline/services/mmnv/IRequest.cpp b/app/src/main/cpp/skyline/services/mmnv/IRequest.cpp index 68bd5cb2..646af781 100644 --- a/app/src/main/cpp/skyline/services/mmnv/IRequest.cpp +++ b/app/src/main/cpp/skyline/services/mmnv/IRequest.cpp @@ -25,7 +25,7 @@ namespace skyline::service::mmnv { request.Skip(); // Unknown unused param in HOS //u32 autoClear{request.Pop()}; - std::lock_guard lock(requestsMutex); + std::scoped_lock lock{requestsMutex}; AllocateRequest().request.module = module; return {}; @@ -34,7 +34,7 @@ namespace skyline::service::mmnv { Result IRequest::FinalizeOld(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { auto module{request.Pop()}; - std::lock_guard lock(requestsMutex); + std::scoped_lock lock{requestsMutex}; for (auto &req : requests) { if (req && req->module == module) { req.reset(); @@ -49,7 +49,7 @@ namespace skyline::service::mmnv { auto module{request.Pop()}; u32 freqHz{request.Pop()}; - std::lock_guard lock(requestsMutex); + std::scoped_lock lock{requestsMutex}; for (auto &req : requests) { if (req && req->module == module) { req->freqHz = freqHz; @@ -67,7 +67,7 @@ namespace skyline::service::mmnv { Result IRequest::GetOld(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { auto module{request.Pop()}; - std::lock_guard lock(requestsMutex); + std::scoped_lock lock{requestsMutex}; for (auto &req : requests) { if (req && req->module == module) { Logger::Debug("Get frequency for module {}: {} Hz", static_cast(module), req->freqHz); @@ -87,7 +87,7 @@ namespace skyline::service::mmnv { request.Skip(); // Unknown unused param in HOS //u32 autoClear{request.Pop()}; - std::lock_guard lock(requestsMutex); + std::scoped_lock lock{requestsMutex}; auto req{AllocateRequest()}; req.request.module = module; response.Push(req.id); @@ -97,7 +97,7 @@ namespace skyline::service::mmnv { Result IRequest::Finalize(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { u32 id{request.Pop()}; - std::lock_guard lock(requestsMutex); + std::scoped_lock lock{requestsMutex}; if (id >= requests.size()) return {}; @@ -109,7 +109,7 @@ namespace skyline::service::mmnv { u32 id{request.Pop()}; u32 freqHz{request.Pop()}; - std::lock_guard lock(requestsMutex); + std::scoped_lock lock{requestsMutex}; if (id < requests.size()) { auto &req{requests[id]}; if (req) { @@ -127,7 +127,7 @@ namespace skyline::service::mmnv { Result IRequest::Get(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { u32 id{request.Pop()}; - std::lock_guard lock(requestsMutex); + std::scoped_lock lock{requestsMutex}; if (id < requests.size()) { auto &req{requests[id]}; if (req) { diff --git a/app/src/main/cpp/skyline/services/nvdrv/core/syncpoint_manager.cpp b/app/src/main/cpp/skyline/services/nvdrv/core/syncpoint_manager.cpp index e56f7a1d..42dc04a0 100644 --- a/app/src/main/cpp/skyline/services/nvdrv/core/syncpoint_manager.cpp +++ b/app/src/main/cpp/skyline/services/nvdrv/core/syncpoint_manager.cpp @@ -40,7 +40,7 @@ namespace skyline::service::nvdrv::core { } u32 SyncpointManager::AllocateSyncpoint(bool clientManaged) { - std::lock_guard lock(reservationLock); + std::scoped_lock lock{reservationLock}; return ReserveSyncpoint(FindFreeSyncpoint(), clientManaged); } diff --git a/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/ctrl.cpp b/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/ctrl.cpp index 919f1218..88daa907 100644 --- a/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/ctrl.cpp +++ b/app/src/main/cpp/skyline/services/nvdrv/devices/nvhost/ctrl.cpp @@ -102,7 +102,7 @@ namespace skyline::service::nvdrv::device::nvhost { if (!timeout) return PosixResult::TryAgain; - std::lock_guard lock(syncpointEventMutex); + std::scoped_lock lock{syncpointEventMutex}; u32 slot = [&]() { if (allocate) { @@ -165,7 +165,7 @@ namespace skyline::service::nvdrv::device::nvhost { if (slot >= SyncpointEventCount) return PosixResult::InvalidArgument; - std::lock_guard lock(syncpointEventMutex); + std::scoped_lock lock{syncpointEventMutex}; auto &event{syncpointEvents[slot]}; if (!event) @@ -197,7 +197,7 @@ namespace skyline::service::nvdrv::device::nvhost { if (slot >= SyncpointEventCount) return PosixResult::InvalidArgument; - std::lock_guard lock(syncpointEventMutex); + std::scoped_lock lock{syncpointEventMutex}; auto &event{syncpointEvents[slot]}; if (event) // Recreate event if it already exists @@ -212,7 +212,7 @@ namespace skyline::service::nvdrv::device::nvhost { PosixResult Ctrl::SyncpointFreeEvent(In slot) { Logger::Debug("slot: {}", slot); - std::lock_guard lock(syncpointEventMutex); + std::scoped_lock lock{syncpointEventMutex}; return SyncpointFreeEventLocked(slot); } @@ -222,7 +222,7 @@ namespace skyline::service::nvdrv::device::nvhost { auto err{PosixResult::Success}; // Avoid repeated locks/unlocks by just locking now - std::lock_guard lock(syncpointEventMutex); + std::scoped_lock lock{syncpointEventMutex}; for (u32 i{}; i < std::numeric_limits::digits; i++) if (bitmask & (1ULL << i)) @@ -242,7 +242,7 @@ namespace skyline::service::nvdrv::device::nvhost { u32 syncpointId{value.eventAllocated ? static_cast(value.syncpointIdForAllocation) : value.syncpointId}; - std::lock_guard lock(syncpointEventMutex); + std::scoped_lock lock{syncpointEventMutex}; auto &event{syncpointEvents[slot]}; if (event && event->fence.id == syncpointId) diff --git a/app/src/main/cpp/skyline/services/serviceman.cpp b/app/src/main/cpp/skyline/services/serviceman.cpp index 0cdc816d..d239d16c 100644 --- a/app/src/main/cpp/skyline/services/serviceman.cpp +++ b/app/src/main/cpp/skyline/services/serviceman.cpp @@ -116,7 +116,7 @@ namespace skyline::service { } std::shared_ptr ServiceManager::NewService(ServiceName name, type::KSession &session, ipc::IpcResponse &response) { - std::lock_guard serviceGuard(mutex); + std::scoped_lock serviceGuard{mutex}; auto serviceObject{CreateOrGetService(name)}; KHandle handle{}; if (session.isDomain) { @@ -132,7 +132,7 @@ namespace skyline::service { } void ServiceManager::RegisterService(std::shared_ptr serviceObject, type::KSession &session, ipc::IpcResponse &response) { // NOLINT(performance-unnecessary-value-param) - std::lock_guard serviceGuard(mutex); + std::scoped_lock serviceGuard{mutex}; KHandle handle{}; if (session.isDomain) { @@ -148,7 +148,7 @@ namespace skyline::service { } void ServiceManager::CloseSession(KHandle handle) { - std::lock_guard serviceGuard(mutex); + std::scoped_lock serviceGuard{mutex}; auto session{state.process->GetHandle(handle)}; if (session->isOpen) { if (session->isDomain) { diff --git a/app/src/main/cpp/skyline/services/timesrv/core.cpp b/app/src/main/cpp/skyline/services/timesrv/core.cpp index f6f03091..3068ada2 100644 --- a/app/src/main/cpp/skyline/services/timesrv/core.cpp +++ b/app/src/main/cpp/skyline/services/timesrv/core.cpp @@ -51,7 +51,7 @@ namespace skyline::service::timesrv::core { } TimeSpanType StandardSteadyClockCore::GetRawTimePoint() { - std::lock_guard lock(mutex); + std::scoped_lock lock{mutex}; auto timePoint{TimeSpanType::FromNanoseconds(util::GetTimeNs()) + rtcOffset}; if (timePoint > cachedValue) diff --git a/app/src/main/cpp/skyline/services/timesrv/time_shared_memory.cpp b/app/src/main/cpp/skyline/services/timesrv/time_shared_memory.cpp index 15c10459..e48046b9 100644 --- a/app/src/main/cpp/skyline/services/timesrv/time_shared_memory.cpp +++ b/app/src/main/cpp/skyline/services/timesrv/time_shared_memory.cpp @@ -99,14 +99,14 @@ namespace skyline::service::timesrv::core { } void SystemClockContextUpdateCallback::SignalOperationEvent() { - std::lock_guard lock(mutex); + std::scoped_lock lock{mutex}; for (const auto &event : operationEvents) event->Signal(); } void SystemClockContextUpdateCallback::AddOperationEvent(const std::shared_ptr &event) { - std::lock_guard lock(mutex); + std::scoped_lock lock{mutex}; operationEvents.push_back(event); } diff --git a/app/src/main/cpp/skyline/services/timesrv/timezone_manager.cpp b/app/src/main/cpp/skyline/services/timesrv/timezone_manager.cpp index 5874209f..27ef0d8f 100644 --- a/app/src/main/cpp/skyline/services/timesrv/timezone_manager.cpp +++ b/app/src/main/cpp/skyline/services/timesrv/timezone_manager.cpp @@ -16,7 +16,7 @@ namespace skyline::service::timesrv::core { } ResultValue TimeZoneManager::GetLocationName() { - std::lock_guard lock(mutex); + std::scoped_lock lock{mutex}; if (!IsInitialized()) return result::ClockUninitialized; @@ -25,7 +25,7 @@ namespace skyline::service::timesrv::core { } Result TimeZoneManager::SetNewLocation(std::string_view pLocationName, span binary) { - std::lock_guard lock(mutex); + std::scoped_lock lock{mutex}; rule = tz_tzalloc(binary.data(), static_cast(binary.size())); if (!rule) @@ -37,7 +37,7 @@ namespace skyline::service::timesrv::core { } ResultValue TimeZoneManager::GetUpdateTime() { - std::lock_guard lock(mutex); + std::scoped_lock lock{mutex}; if (!IsInitialized()) return result::ClockUninitialized; @@ -46,12 +46,12 @@ namespace skyline::service::timesrv::core { } void TimeZoneManager::SetUpdateTime(const SteadyClockTimePoint &pUpdateTime) { - std::lock_guard lock(mutex); + std::scoped_lock lock{mutex}; updateTime = pUpdateTime; } ResultValue TimeZoneManager::GetLocationCount() { - std::lock_guard lock(mutex); + std::scoped_lock lock{mutex}; if (!IsInitialized()) return result::ClockUninitialized; @@ -60,12 +60,12 @@ namespace skyline::service::timesrv::core { } void TimeZoneManager::SetLocationCount(int pLocationCount) { - std::lock_guard lock(mutex); + std::scoped_lock lock{mutex}; locationCount = pLocationCount; } ResultValue> TimeZoneManager::GetBinaryVersion() { - std::lock_guard lock(mutex); + std::scoped_lock lock{mutex}; if (!IsInitialized()) return result::ClockUninitialized; @@ -74,7 +74,7 @@ namespace skyline::service::timesrv::core { } void TimeZoneManager::SetBinaryVersion(std::array pBinaryVersion) { - std::lock_guard lock(mutex); + std::scoped_lock lock{mutex}; binaryVersion = pBinaryVersion; } diff --git a/app/src/main/cpp/skyline/vfs/ctr_encrypted_backing.cpp b/app/src/main/cpp/skyline/vfs/ctr_encrypted_backing.cpp index 9cfb93d0..51661ec3 100644 --- a/app/src/main/cpp/skyline/vfs/ctr_encrypted_backing.cpp +++ b/app/src/main/cpp/skyline/vfs/ctr_encrypted_backing.cpp @@ -29,7 +29,7 @@ namespace skyline::vfs { if (read != size) return 0; { - std::lock_guard guard(mutex); + std::scoped_lock guard{mutex}; UpdateCtr(baseOffset + offset); cipher.Decrypt(output); } @@ -42,7 +42,7 @@ namespace skyline::vfs { if (read != SectorSize) return 0; { - std::lock_guard guard(mutex); + std::scoped_lock guard{mutex}; UpdateCtr(baseOffset + sectorStart); cipher.Decrypt(blockBuf); }