From 529024448e675c7ef52439914f93e466a987b3c7 Mon Sep 17 00:00:00 2001 From: TuxSH Date: Thu, 15 Nov 2018 11:49:32 +0100 Subject: [PATCH] meso: introduce ProcessState --- .../include/mesosphere/core/KAutoObject.hpp | 1 + .../include/mesosphere/processes/KProcess.hpp | 27 ++++++++++++++-- mesosphere/source/processes/KProcess.cpp | 31 +++++++++++++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/mesosphere/include/mesosphere/core/KAutoObject.hpp b/mesosphere/include/mesosphere/core/KAutoObject.hpp index 983167460..a400ebb4b 100644 --- a/mesosphere/include/mesosphere/core/KAutoObject.hpp +++ b/mesosphere/include/mesosphere/core/KAutoObject.hpp @@ -38,6 +38,7 @@ MESOSPHERE_AUTO_OBJECT_FW_DECL(LightServerSession); MESOSPHERE_AUTO_OBJECT_FW_DECL(Port); MESOSPHERE_AUTO_OBJECT_FW_DECL(ClientPort); MESOSPHERE_AUTO_OBJECT_FW_DECL(ServerPort); +MESOSPHERE_AUTO_OBJECT_FW_DECL(Debug); class KAutoObject { public: diff --git a/mesosphere/include/mesosphere/processes/KProcess.hpp b/mesosphere/include/mesosphere/processes/KProcess.hpp index 924670616..58f164117 100644 --- a/mesosphere/include/mesosphere/processes/KProcess.hpp +++ b/mesosphere/include/mesosphere/processes/KProcess.hpp @@ -4,17 +4,30 @@ class KThread; class KResourceLimit; #include -#include +#include #include #include namespace mesosphere { -class KProcess final : public KAutoObject { +class KProcess final : public KSynchronizationObject /* FIXME */ { public: 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; } void IncrementSchedulerOperationCount() { ++schedulerOperationCount; } @@ -24,11 +37,21 @@ class KProcess final : public KAutoObject { KHandleTable &GetHandleTable() { return handleTable; } + constexpr State GetState() const { return state; } + + KDebug *GetDebug() const { return debug; } + void SetDebug(KDebug *debug); + void ClearDebug(State attachState); + private: KThread *lastThreads[MAX_CORES]{nullptr}; ulong lastIdleSelectionCount[MAX_CORES]{0}; long schedulerOperationCount = -1; + State state = State::Created; + bool stateChanged = false; + + KDebug *debug = nullptr; SharedPtr reslimit{}; KHandleTable handleTable{}; }; diff --git a/mesosphere/source/processes/KProcess.cpp b/mesosphere/source/processes/KProcess.cpp index 75d7d0eef..35fe15698 100644 --- a/mesosphere/source/processes/KProcess.cpp +++ b/mesosphere/source/processes/KProcess.cpp @@ -11,4 +11,35 @@ void KProcess::SetLastThreadAndIdleSelectionCount(KThread *thread, ulong idleSel 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(); + } +} + }