mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-08 13:11:49 +00:00
meso: introduce ProcessState
This commit is contained in:
parent
757aa30e74
commit
529024448e
3 changed files with 57 additions and 2 deletions
|
@ -38,6 +38,7 @@ MESOSPHERE_AUTO_OBJECT_FW_DECL(LightServerSession);
|
||||||
MESOSPHERE_AUTO_OBJECT_FW_DECL(Port);
|
MESOSPHERE_AUTO_OBJECT_FW_DECL(Port);
|
||||||
MESOSPHERE_AUTO_OBJECT_FW_DECL(ClientPort);
|
MESOSPHERE_AUTO_OBJECT_FW_DECL(ClientPort);
|
||||||
MESOSPHERE_AUTO_OBJECT_FW_DECL(ServerPort);
|
MESOSPHERE_AUTO_OBJECT_FW_DECL(ServerPort);
|
||||||
|
MESOSPHERE_AUTO_OBJECT_FW_DECL(Debug);
|
||||||
|
|
||||||
class KAutoObject {
|
class KAutoObject {
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -4,17 +4,30 @@ class KThread;
|
||||||
class KResourceLimit;
|
class KResourceLimit;
|
||||||
|
|
||||||
#include <mesosphere/core/util.hpp>
|
#include <mesosphere/core/util.hpp>
|
||||||
#include <mesosphere/core/KAutoObject.hpp>
|
#include <mesosphere/core/KSynchronizationObject.hpp>
|
||||||
#include <mesosphere/interfaces/ISetAllocated.hpp>
|
#include <mesosphere/interfaces/ISetAllocated.hpp>
|
||||||
#include <mesosphere/processes/KHandleTable.hpp>
|
#include <mesosphere/processes/KHandleTable.hpp>
|
||||||
|
|
||||||
namespace mesosphere
|
namespace mesosphere
|
||||||
{
|
{
|
||||||
|
|
||||||
class KProcess final : public KAutoObject {
|
class KProcess final : public KSynchronizationObject /* FIXME */ {
|
||||||
public:
|
public:
|
||||||
MESOSPHERE_AUTO_OBJECT_TRAITS(AutoObject, Process);
|
MESOSPHERE_AUTO_OBJECT_TRAITS(AutoObject, Process);
|
||||||
|
|
||||||
|
enum class State : uint {
|
||||||
|
Created = 0,
|
||||||
|
CreatedAttached,
|
||||||
|
Started,
|
||||||
|
Crashed,
|
||||||
|
StartedAttached,
|
||||||
|
Exiting,
|
||||||
|
Exited,
|
||||||
|
DebugSuspended,
|
||||||
|
};
|
||||||
|
|
||||||
|
virtual bool IsSignaled() const override;
|
||||||
|
|
||||||
constexpr long GetSchedulerOperationCount() const { return schedulerOperationCount; }
|
constexpr long GetSchedulerOperationCount() const { return schedulerOperationCount; }
|
||||||
|
|
||||||
void IncrementSchedulerOperationCount() { ++schedulerOperationCount; }
|
void IncrementSchedulerOperationCount() { ++schedulerOperationCount; }
|
||||||
|
@ -24,11 +37,21 @@ class KProcess final : public KAutoObject {
|
||||||
|
|
||||||
KHandleTable &GetHandleTable() { return handleTable; }
|
KHandleTable &GetHandleTable() { return handleTable; }
|
||||||
|
|
||||||
|
constexpr State GetState() const { return state; }
|
||||||
|
|
||||||
|
KDebug *GetDebug() const { return debug; }
|
||||||
|
void SetDebug(KDebug *debug);
|
||||||
|
void ClearDebug(State attachState);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KThread *lastThreads[MAX_CORES]{nullptr};
|
KThread *lastThreads[MAX_CORES]{nullptr};
|
||||||
ulong lastIdleSelectionCount[MAX_CORES]{0};
|
ulong lastIdleSelectionCount[MAX_CORES]{0};
|
||||||
long schedulerOperationCount = -1;
|
long schedulerOperationCount = -1;
|
||||||
|
|
||||||
|
State state = State::Created;
|
||||||
|
bool stateChanged = false;
|
||||||
|
|
||||||
|
KDebug *debug = nullptr;
|
||||||
SharedPtr<KResourceLimit> reslimit{};
|
SharedPtr<KResourceLimit> reslimit{};
|
||||||
KHandleTable handleTable{};
|
KHandleTable handleTable{};
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,4 +11,35 @@ void KProcess::SetLastThreadAndIdleSelectionCount(KThread *thread, ulong idleSel
|
||||||
lastIdleSelectionCount[thread->GetCurrentCoreId()] = idleSelectionCount;
|
lastIdleSelectionCount[thread->GetCurrentCoreId()] = idleSelectionCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool KProcess::IsSignaled() const
|
||||||
|
{
|
||||||
|
return stateChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KProcess::SetDebug(KDebug *debug)
|
||||||
|
{
|
||||||
|
this->debug = debug;
|
||||||
|
if (state != State::DebugSuspended) {
|
||||||
|
state = state == State::Created ? State::CreatedAttached : State::DebugSuspended;
|
||||||
|
stateChanged = true;
|
||||||
|
NotifyWaiters();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void KProcess::ClearDebug(KProcess::State attachState)
|
||||||
|
{
|
||||||
|
debug = nullptr;
|
||||||
|
State oldState = state;
|
||||||
|
if (state == State::StartedAttached || state == State::DebugSuspended) {
|
||||||
|
state = attachState == State::Created ? State::Started : attachState; // Restore the old state
|
||||||
|
} else if (state == State::CreatedAttached) {
|
||||||
|
state = State::Created;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state != oldState) {
|
||||||
|
stateChanged = true;
|
||||||
|
NotifyWaiters();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue