mesosphere: Add convenience KScopedCriticalSection

This commit is contained in:
Michael Scire 2018-11-05 03:47:15 -08:00
parent 9b1fb0c6df
commit 600afa5f0f
4 changed files with 16 additions and 8 deletions

View file

@ -1,6 +1,7 @@
#pragma once
#include <array>
#include <mutex>
#include <mesosphere/core/util.hpp>
#include <mesosphere/threading/KMultiLevelQueue.hpp>
#include <mesosphere/threading/KThread.hpp>
@ -127,4 +128,11 @@ class KScheduler {
}
};
// Convenience
class KScopedCriticalSection {
private:
std::scoped_lock<KCriticalSection> lk{KScheduler::GetCriticalSection()};
};
}

View file

@ -13,9 +13,9 @@ KSynchronizationObject::~KSynchronizationObject()
{
}
void KSynchronizationObject::Signal()
void KSynchronizationObject::NotifyWaiters()
{
std::lock_guard criticalSection{KScheduler::GetCriticalSection()};
KScopedCriticalSection critical_section;
if (IsSignaled()) {
for (auto &&waiter : waiters) {

View file

@ -36,7 +36,7 @@ void KMutex::lock_slow_path(KThread &owner, KThread &requester)
void KMutex::unlock_slow_path(KThread &owner)
{
std::lock_guard criticalSection{KScheduler::GetCriticalSection()};
KScopedCriticalSection critical_section;
size_t count;
KThread *newOwner = owner.RelinquishMutex(&count, (uiptr)this);
native_handle_type newTag;

View file

@ -46,7 +46,7 @@ void KThread::RescheduleIfStatusEquals(SchedulingStatus expectedStatus, Scheduli
void KThread::AddForcePauseReason(KThread::ForcePauseReason reason)
{
std::lock_guard criticalSection{KScheduler::GetCriticalSection()};
KScopedCriticalSection critical_section;
if (!IsDying()) {
AddForcePauseReasonToField(reason);
@ -58,7 +58,7 @@ void KThread::AddForcePauseReason(KThread::ForcePauseReason reason)
void KThread::RemoveForcePauseReason(KThread::ForcePauseReason reason)
{
std::lock_guard criticalSection{KScheduler::GetCriticalSection()};
KScopedCriticalSection critical_section;
if (!IsDying()) {
RemoveForcePauseReasonToField(reason);
@ -104,7 +104,7 @@ void KThread::ResumeAllFromKernelSync(KThread::WaitList &waitList)
void KThread::CancelKernelSync()
{
std::lock_guard criticalSection{KScheduler::GetCriticalSection()};
KScopedCriticalSection critical_section;
if (GetSchedulingStatus() == SchedulingStatus::Paused) {
// Note: transparent to force-pause
if (currentWaitList != nullptr) {
@ -136,7 +136,7 @@ Result KThread::WaitSynchronizationImpl(int &outId, KSynchronizationObject **syn
outId = -1;
{
std::lock_guard criticalSection{KScheduler::GetCriticalSection()};
KScopedCriticalSection critical_section;
// Try to find an already signaled object.
if (numSyncObjs >= 1) {
@ -178,7 +178,7 @@ Result KThread::WaitSynchronizationImpl(int &outId, KSynchronizationObject **syn
// Now waiting...
{
std::lock_guard criticalSection{KScheduler::GetCriticalSection()};
KScopedCriticalSection critical_section;
isWaitingSync = false;
if (timeoutTime > KSystemClock::time_point{}) {