mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-01-10 11:26:15 +00:00
mesosphere: Add convenience KScopedCriticalSection
This commit is contained in:
parent
9b1fb0c6df
commit
600afa5f0f
4 changed files with 16 additions and 8 deletions
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <mutex>
|
||||||
#include <mesosphere/core/util.hpp>
|
#include <mesosphere/core/util.hpp>
|
||||||
#include <mesosphere/threading/KMultiLevelQueue.hpp>
|
#include <mesosphere/threading/KMultiLevelQueue.hpp>
|
||||||
#include <mesosphere/threading/KThread.hpp>
|
#include <mesosphere/threading/KThread.hpp>
|
||||||
|
@ -127,4 +128,11 @@ class KScheduler {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Convenience
|
||||||
|
|
||||||
|
class KScopedCriticalSection {
|
||||||
|
private:
|
||||||
|
std::scoped_lock<KCriticalSection> lk{KScheduler::GetCriticalSection()};
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,9 +13,9 @@ KSynchronizationObject::~KSynchronizationObject()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void KSynchronizationObject::Signal()
|
void KSynchronizationObject::NotifyWaiters()
|
||||||
{
|
{
|
||||||
std::lock_guard criticalSection{KScheduler::GetCriticalSection()};
|
KScopedCriticalSection critical_section;
|
||||||
|
|
||||||
if (IsSignaled()) {
|
if (IsSignaled()) {
|
||||||
for (auto &&waiter : waiters) {
|
for (auto &&waiter : waiters) {
|
||||||
|
|
|
@ -36,7 +36,7 @@ void KMutex::lock_slow_path(KThread &owner, KThread &requester)
|
||||||
|
|
||||||
void KMutex::unlock_slow_path(KThread &owner)
|
void KMutex::unlock_slow_path(KThread &owner)
|
||||||
{
|
{
|
||||||
std::lock_guard criticalSection{KScheduler::GetCriticalSection()};
|
KScopedCriticalSection critical_section;
|
||||||
size_t count;
|
size_t count;
|
||||||
KThread *newOwner = owner.RelinquishMutex(&count, (uiptr)this);
|
KThread *newOwner = owner.RelinquishMutex(&count, (uiptr)this);
|
||||||
native_handle_type newTag;
|
native_handle_type newTag;
|
||||||
|
|
|
@ -46,7 +46,7 @@ void KThread::RescheduleIfStatusEquals(SchedulingStatus expectedStatus, Scheduli
|
||||||
|
|
||||||
void KThread::AddForcePauseReason(KThread::ForcePauseReason reason)
|
void KThread::AddForcePauseReason(KThread::ForcePauseReason reason)
|
||||||
{
|
{
|
||||||
std::lock_guard criticalSection{KScheduler::GetCriticalSection()};
|
KScopedCriticalSection critical_section;
|
||||||
|
|
||||||
if (!IsDying()) {
|
if (!IsDying()) {
|
||||||
AddForcePauseReasonToField(reason);
|
AddForcePauseReasonToField(reason);
|
||||||
|
@ -58,7 +58,7 @@ void KThread::AddForcePauseReason(KThread::ForcePauseReason reason)
|
||||||
|
|
||||||
void KThread::RemoveForcePauseReason(KThread::ForcePauseReason reason)
|
void KThread::RemoveForcePauseReason(KThread::ForcePauseReason reason)
|
||||||
{
|
{
|
||||||
std::lock_guard criticalSection{KScheduler::GetCriticalSection()};
|
KScopedCriticalSection critical_section;
|
||||||
|
|
||||||
if (!IsDying()) {
|
if (!IsDying()) {
|
||||||
RemoveForcePauseReasonToField(reason);
|
RemoveForcePauseReasonToField(reason);
|
||||||
|
@ -104,7 +104,7 @@ void KThread::ResumeAllFromKernelSync(KThread::WaitList &waitList)
|
||||||
|
|
||||||
void KThread::CancelKernelSync()
|
void KThread::CancelKernelSync()
|
||||||
{
|
{
|
||||||
std::lock_guard criticalSection{KScheduler::GetCriticalSection()};
|
KScopedCriticalSection critical_section;
|
||||||
if (GetSchedulingStatus() == SchedulingStatus::Paused) {
|
if (GetSchedulingStatus() == SchedulingStatus::Paused) {
|
||||||
// Note: transparent to force-pause
|
// Note: transparent to force-pause
|
||||||
if (currentWaitList != nullptr) {
|
if (currentWaitList != nullptr) {
|
||||||
|
@ -136,7 +136,7 @@ Result KThread::WaitSynchronizationImpl(int &outId, KSynchronizationObject **syn
|
||||||
|
|
||||||
outId = -1;
|
outId = -1;
|
||||||
{
|
{
|
||||||
std::lock_guard criticalSection{KScheduler::GetCriticalSection()};
|
KScopedCriticalSection critical_section;
|
||||||
|
|
||||||
// Try to find an already signaled object.
|
// Try to find an already signaled object.
|
||||||
if (numSyncObjs >= 1) {
|
if (numSyncObjs >= 1) {
|
||||||
|
@ -178,7 +178,7 @@ Result KThread::WaitSynchronizationImpl(int &outId, KSynchronizationObject **syn
|
||||||
// Now waiting...
|
// Now waiting...
|
||||||
|
|
||||||
{
|
{
|
||||||
std::lock_guard criticalSection{KScheduler::GetCriticalSection()};
|
KScopedCriticalSection critical_section;
|
||||||
|
|
||||||
isWaitingSync = false;
|
isWaitingSync = false;
|
||||||
if (timeoutTime > KSystemClock::time_point{}) {
|
if (timeoutTime > KSystemClock::time_point{}) {
|
||||||
|
|
Loading…
Reference in a new issue