Refactor all std::lock_guard usages to std::scoped_lock

This commit is contained in:
Billy Laws 2022-04-25 15:00:30 +01:00
parent 94e6f3cfa0
commit 1dd230afde
22 changed files with 87 additions and 87 deletions

View File

@ -23,7 +23,7 @@ namespace skyline::audio {
}
std::shared_ptr<AudioTrack> Audio::OpenTrack(u8 channelCount, u32 sampleRate, const std::function<void()> &releaseCallback) {
std::lock_guard trackGuard(trackLock);
std::scoped_lock trackGuard{trackLock};
auto track{std::make_shared<AudioTrack>(channelCount, sampleRate, releaseCallback)};
audioTracks.push_back(track);
@ -32,7 +32,7 @@ namespace skyline::audio {
}
void Audio::CloseTrack(std::shared_ptr<AudioTrack> &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<i16, i32>(static_cast<u32>(*destination) + static_cast<u32>(*source));

View File

@ -29,7 +29,7 @@ namespace skyline {
* @return The amount of data written into the input buffer in units of Type
*/
size_t Read(span <Type> 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 <Type> buffer) {
std::lock_guard guard(mtx);
std::scoped_lock guard{mtx};
Type *pointer{buffer.data()};
ssize_t size{static_cast<ssize_t>(buffer.size())};

View File

@ -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;
}
}

View File

@ -21,11 +21,11 @@ namespace skyline::gpu {
mirror = alignedMirror.subspan(static_cast<size_t>(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);

View File

@ -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<u32>(std::min(static_cast<i32>(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) {

View File

@ -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,

View File

@ -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);

View File

@ -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 = {};

View File

@ -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<type::KThread> &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<type::KThread> &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};

View File

@ -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<u8>(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;

View File

@ -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<KThread> KProcess::CreateThread(void *entry, u64 argument, void *stackTop, std::optional<i8> priority, std::optional<u8> 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<KThread> &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<KThread>{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)

View File

@ -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;

View File

@ -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);

View File

@ -31,7 +31,7 @@ namespace skyline::service::hid {
Result IHidServer::SetSupportedNpadStyleSet(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
auto styleSet{request.Pop<NpadStyleSet>()};
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<NpadId>()};
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<u64>();
state.input->npad.orientation = request.Pop<NpadJoyOrientation>();
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<NpadId>()};
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<NpadId>()};
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<NpadId>()};
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 {};

View File

@ -25,7 +25,7 @@ namespace skyline::service::mmnv {
request.Skip<u32>(); // Unknown unused param in HOS
//u32 autoClear{request.Pop<u32>()};
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<ModuleType>()};
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<ModuleType>()};
u32 freqHz{request.Pop<u32>()};
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<ModuleType>()};
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<u32>(module), req->freqHz);
@ -87,7 +87,7 @@ namespace skyline::service::mmnv {
request.Skip<u32>(); // Unknown unused param in HOS
//u32 autoClear{request.Pop<u32>()};
std::lock_guard lock(requestsMutex);
std::scoped_lock lock{requestsMutex};
auto req{AllocateRequest()};
req.request.module = module;
response.Push<u32>(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<u32>()};
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>()};
u32 freqHz{request.Pop<u32>()};
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<u32>()};
std::lock_guard lock(requestsMutex);
std::scoped_lock lock{requestsMutex};
if (id < requests.size()) {
auto &req{requests[id]};
if (req) {

View File

@ -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);
}

View File

@ -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<u32> 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<u64>::digits; i++)
if (bitmask & (1ULL << i))
@ -242,7 +242,7 @@ namespace skyline::service::nvdrv::device::nvhost {
u32 syncpointId{value.eventAllocated ? static_cast<u32>(value.syncpointIdForAllocation) : value.syncpointId};
std::lock_guard lock(syncpointEventMutex);
std::scoped_lock lock{syncpointEventMutex};
auto &event{syncpointEvents[slot]};
if (event && event->fence.id == syncpointId)

View File

@ -116,7 +116,7 @@ namespace skyline::service {
}
std::shared_ptr<BaseService> 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<BaseService> 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<type::KSession>(handle)};
if (session->isOpen) {
if (session->isDomain) {

View File

@ -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)

View File

@ -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<kernel::type::KEvent> &event) {
std::lock_guard lock(mutex);
std::scoped_lock lock{mutex};
operationEvents.push_back(event);
}

View File

@ -16,7 +16,7 @@ namespace skyline::service::timesrv::core {
}
ResultValue<LocationName> 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<u8> binary) {
std::lock_guard lock(mutex);
std::scoped_lock lock{mutex};
rule = tz_tzalloc(binary.data(), static_cast<long>(binary.size()));
if (!rule)
@ -37,7 +37,7 @@ namespace skyline::service::timesrv::core {
}
ResultValue<SteadyClockTimePoint> 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<int> 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<std::array<u8, 0x10>> 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<u8, 0x10> pBinaryVersion) {
std::lock_guard lock(mutex);
std::scoped_lock lock{mutex};
binaryVersion = pBinaryVersion;
}

View File

@ -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);
}