Add KInterruptBottomHalfGuard

This commit is contained in:
TuxSH 2018-11-07 12:03:25 +01:00 committed by Michael Scire
parent 40b860c239
commit 7b726c3184
7 changed files with 47 additions and 11 deletions

View file

@ -0,0 +1,32 @@
#pragma once
#include <mesosphere/core/KCoreContext.hpp>
namespace mesosphere
{
class KThread;
inline void IncrementThreadInterruptBottomHalfLockCount(KThread &thread);
inline void DecrementThreadInterruptBottomHalfLockCount(KThread &thread);
class KInterruptBottomHalfGuard final {
public:
KInterruptBottomHalfGuard()
{
KThread *curThread = KCoreContext::GetCurrentInstance().GetCurrentThread();
IncrementInterruptBottomHalfLockCount(*curThread);
}
~KInterruptBottomHalfGuard()
{
KThread *curThread = KCoreContext::GetCurrentInstance().GetCurrentThread();
DecrementInterruptBottomHalfLockCount(*curThread);
}
KInterruptBottomHalfGuard(const KInterruptBottomHalfGuard &) = delete;
KInterruptBottomHalfGuard(KInterruptBottomHalfGuard &&) = delete;
KInterruptBottomHalfGuard &operator=(const KInterruptBottomHalfGuard &) = delete;
KInterruptBottomHalfGuard &operator=(KInterruptBottomHalfGuard &&) = delete;
};
}

View file

@ -33,7 +33,7 @@ class KThread final :
MESOSPHERE_AUTO_OBJECT_TRAITS(AutoObject, Thread);
MESOSPHERE_LIMITED_RESOURCE_TRAITS(100ms);
class StackParameters {
class StackParameters final {
public:
StackParameters(std::array<u64, 4> svcPermissionMask, KThreadContext *threadCtx) :
svcPermissionMask{svcPermissionMask}, threadCtx{threadCtx} {}
@ -46,19 +46,19 @@ class KThread final :
constexpr bool IsExecutingSvc() const { return isExecutingSvc; }
constexpr u8 GetCurrentSvcId() const { return currentSvcId; }
constexpr uint GetBottomHalfLockCount() const { return bottomHalfLockCount; }
void IncrementBottomHalfLockCount() { ++bottomHalfLockCount; }
void DecrementBottomHalfLockCount() { --bottomHalfLockCount; }
constexpr uint GetInterruptBottomHalfLockCount() const { return interruptBottomHalfLockCount; }
void IncrementInterruptBottomHalfLockCount() { ++interruptBottomHalfLockCount; }
void DecrementInterruptBottomHalfLockCount() { --interruptBottomHalfLockCount; }
KThreadContext *GetThreadContext() const { return threadCtx; }
private:
std::array<u64, 4> svcPermissionMask[256/64]{};
u8 stateFlags = 0;
u8 currentSvcId = 0;
bool isExecutingSvc = false;
bool isNotStarted = true;
uint bottomHalfLockCount = 1;
uint interruptBottomHalfLockCount = 1;
KThreadContext *threadCtx = nullptr;
};
@ -265,6 +265,15 @@ class KThread final :
KThread(KProcess *owner, u64 id, uint priority) : KAutoObject(), owner(owner), schedulerNodes(),
id(id), basePriority(priority), priority(priority),
currentCoreId(0), affinityMask(15) {};
friend void IncrementThreadInterruptBottomHalfLockCount(KThread &thread)
{
thread.GetStackParameters().IncrementInterruptBottomHalfLockCount();
}
friend void DecrementThreadInterruptBottomHalfLockCount(KThread &thread)
{
thread.GetStackParameters().DecrementInterruptBottomHalfLockCount();
}
private:
Result WaitSynchronizationImpl(int &outId, KSynchronizationObject **syncObjs, int numSyncObjs, const KSystemClock::time_point &timeoutTime);

View file

@ -1,6 +1,5 @@
#include <mesosphere/core/KSynchronizationObject.hpp>
#include <mesosphere/core/Result.hpp>
#include <mesosphere/core/KCoreContext.hpp>
#include <mesosphere/threading/KScheduler.hpp>
#include <mesosphere/threading/KThread.hpp>

View file

@ -1,5 +1,4 @@
#include <mesosphere/interrupts/KAlarm.hpp>
#include <mesosphere/core/KCoreContext.hpp>
#include <mesosphere/threading/KScheduler.hpp>
#include <mesosphere/arch/KInterruptMaskGuard.hpp>

View file

@ -1,5 +1,4 @@
#include <mesosphere/processes/KEvent.hpp>
#include <mesosphere/core/KCoreContext.hpp>
#include <mesosphere/processes/KProcess.hpp>
namespace mesosphere

View file

@ -1,7 +1,6 @@
#include <mutex>
#include <algorithm>
#include <mesosphere/processes/KHandleTable.hpp>
#include <mesosphere/core/KCoreContext.hpp>
#include <mesosphere/threading/KThread.hpp>
namespace mesosphere

View file

@ -4,7 +4,6 @@
#include <mesosphere/threading/KThread.hpp>
#include <mesosphere/threading/KScheduler.hpp>
#include <mesosphere/core/KCoreContext.hpp>
namespace mesosphere
{