From 698fa9fcb0b534e0b57af954885491f7c50576ba Mon Sep 17 00:00:00 2001 From: TuxSH Date: Mon, 5 Nov 2018 13:57:50 +0100 Subject: [PATCH] Write KEvent::Initialize, fix build issues --- .../include/mesosphere/interfaces/IClient.hpp | 2 +- .../interfaces/IClientServerParent.hpp | 7 +-- .../include/mesosphere/interfaces/IServer.hpp | 7 +-- .../include/mesosphere/processes/KEvent.hpp | 22 +++++---- .../mesosphere/processes/KReadableEvent.hpp | 13 +++-- .../mesosphere/processes/KWritableEvent.hpp | 5 +- .../source/core/KSynchronizationObject.cpp | 2 +- .../source/processes/KReadableEvent.cpp | 48 +++++++++++-------- .../source/processes/KWritableEvent.cpp | 14 ++++-- mesosphere/source/threading/KEvent.cpp | 26 ++++++++++ mesosphere/source/threading/KMutex.cpp | 2 +- mesosphere/source/threading/KThread.cpp | 10 ++-- 12 files changed, 100 insertions(+), 58 deletions(-) create mode 100644 mesosphere/source/threading/KEvent.cpp diff --git a/mesosphere/include/mesosphere/interfaces/IClient.hpp b/mesosphere/include/mesosphere/interfaces/IClient.hpp index 31610ecdd..e3a1f8cd7 100644 --- a/mesosphere/include/mesosphere/interfaces/IClient.hpp +++ b/mesosphere/include/mesosphere/interfaces/IClient.hpp @@ -21,12 +21,12 @@ class IClient { ParentType *GetParent() const { return parent; } - protected: void SetParent(SharedPtr parent) { this->parent = std::move(parent); } + protected: SharedPtr parent{}; }; diff --git a/mesosphere/include/mesosphere/interfaces/IClientServerParent.hpp b/mesosphere/include/mesosphere/interfaces/IClientServerParent.hpp index cb877414c..cdb458346 100644 --- a/mesosphere/include/mesosphere/interfaces/IClientServerParent.hpp +++ b/mesosphere/include/mesosphere/interfaces/IClientServerParent.hpp @@ -12,14 +12,15 @@ class IClientServerParent { using ClientType = Client; using ServerType = Server; - protected: void SetClientServerParent() { - Parent par = (Parent *)this; + Parent *par = (Parent *)this; client.SetParent(par); - server.SetParent(par); + server.SetParentAndClient(par, &client); } + protected: + ClientType client{}; ServerType server{}; }; diff --git a/mesosphere/include/mesosphere/interfaces/IServer.hpp b/mesosphere/include/mesosphere/interfaces/IServer.hpp index d2d9fc00e..e7ea74533 100644 --- a/mesosphere/include/mesosphere/interfaces/IServer.hpp +++ b/mesosphere/include/mesosphere/interfaces/IServer.hpp @@ -21,13 +21,14 @@ class IServer { ParentType *GetParent() const { return parent; } - protected: - void SetParent(SharedPtr parent) + void SetParentAndClient(SharedPtr parent, SharedPtr client) { this->parent = std::move(parent); - this->client = &this->parent->client; + this->client = std::move(client); } + protected: + SharedPtr parent{}; SharedPtr client{}; }; diff --git a/mesosphere/include/mesosphere/processes/KEvent.hpp b/mesosphere/include/mesosphere/processes/KEvent.hpp index 24e49c2e7..a9e974b09 100644 --- a/mesosphere/include/mesosphere/processes/KEvent.hpp +++ b/mesosphere/include/mesosphere/processes/KEvent.hpp @@ -6,6 +6,7 @@ class KProcess; #include #include #include +#include #include #include #include @@ -13,26 +14,27 @@ class KProcess; namespace mesosphere { -class KEvent final : public KAutoObject, IClientServerParent { +class KEvent final : + public KAutoObject, + public IClientServerParent, + public ISetAllocated, + public ILimitedResource { public: MESOSPHERE_AUTO_OBJECT_TRAITS(AutoObject, Event); - - explicit KEvent() : owner(nullptr), is_initialized(false) {} - virtual ~KEvent() {} - - KProcess *GetOwner() const { return this->owner; } - void Initialize(); + + virtual ~KEvent(); + + Result Initialize(); /* KAutoObject */ - virtual bool IsAlive() const override { return is_initialized; } + virtual bool IsAlive() const override; /* IClientServerParent */ void HandleServerDestroyed() { } void HandleClientDestroyed() { } private: - KProcess *owner; - bool is_initialized; + bool isInitialized = false; }; inline void intrusive_ptr_add_ref(KEvent *obj) diff --git a/mesosphere/include/mesosphere/processes/KReadableEvent.hpp b/mesosphere/include/mesosphere/processes/KReadableEvent.hpp index 912602b84..b218bb5a2 100644 --- a/mesosphere/include/mesosphere/processes/KReadableEvent.hpp +++ b/mesosphere/include/mesosphere/processes/KReadableEvent.hpp @@ -16,20 +16,19 @@ class KEvent; class KReadableEvent final : public KSynchronizationObject, public IClient { public: MESOSPHERE_AUTO_OBJECT_TRAITS(SynchronizationObject, ReadableEvent); - + virtual bool IsAlive() const override { return true; } - - explicit KReadableEvent() {} - virtual ~KReadableEvent() {} + + virtual ~KReadableEvent(); Result Signal(); Result Clear(); Result Reset(); - + virtual bool IsSignaled() const override; - + private: - bool is_signaled = false; + bool isSignaled = false; }; inline void intrusive_ptr_add_ref(KReadableEvent *obj) diff --git a/mesosphere/include/mesosphere/processes/KWritableEvent.hpp b/mesosphere/include/mesosphere/processes/KWritableEvent.hpp index 2a92fee77..bf691aecc 100644 --- a/mesosphere/include/mesosphere/processes/KWritableEvent.hpp +++ b/mesosphere/include/mesosphere/processes/KWritableEvent.hpp @@ -17,9 +17,8 @@ class KWritableEvent final : public KAutoObject, public IServeris_signaled; + +bool KReadableEvent::IsSignaled() const +{ + return this->isSignaled; } -Result KReadableEvent::Signal() { - KScopedCriticalSection critical_section; +KReadableEvent::~KReadableEvent() +{ +} + +Result KReadableEvent::Signal() +{ + KScopedCriticalSection criticalSection{}; - if (!this->is_signaled) { - this->is_signaled = true; - this->NotifyWaiters(); + if (!this->isSignaled) { + this->isSignaled = true; + NotifyWaiters(); } - return ResultSuccess(); + return ResultSuccess{}; } -Result KReadableEvent::Clear() { - this->Reset(); - - return ResultSuccess(); +Result KReadableEvent::Clear() +{ + Reset(); + + return ResultSuccess{}; } -Result KReadableEvent::Reset() { - KScopedCriticalSection critical_section; - - if (this->is_signaled) { - this->is_signaled = false; - return ResultSuccess(); +Result KReadableEvent::Reset() +{ + KScopedCriticalSection criticalSection{}; + + if (this->isSignaled) { + this->isSignaled = false; + return ResultSuccess{}; } - return ResultKernelInvalidState(); + return ResultKernelInvalidState{}; } } diff --git a/mesosphere/source/processes/KWritableEvent.cpp b/mesosphere/source/processes/KWritableEvent.cpp index c36690fae..ea6c49952 100644 --- a/mesosphere/source/processes/KWritableEvent.cpp +++ b/mesosphere/source/processes/KWritableEvent.cpp @@ -5,12 +5,18 @@ namespace mesosphere { -Result KWritableEvent::Signal() { - return this->client->Signal(); +KWritableEvent::~KWritableEvent() +{ } -Result KWritableEvent::Clear() { - return this->client->Clear(); +Result KWritableEvent::Signal() +{ + return client->Signal(); +} + +Result KWritableEvent::Clear() +{ + return client->Clear(); } } diff --git a/mesosphere/source/threading/KEvent.cpp b/mesosphere/source/threading/KEvent.cpp new file mode 100644 index 000000000..e68ba0091 --- /dev/null +++ b/mesosphere/source/threading/KEvent.cpp @@ -0,0 +1,26 @@ +#include +#include +#include + +namespace mesosphere +{ + +KEvent::~KEvent() +{ +} + +bool KEvent::IsAlive() const +{ + return isInitialized; +} + +Result KEvent::Initialize() +{ + SetClientServerParent(); + SetResourceOwner(KCoreContext::GetCurrentInstance().GetCurrentProcess()); + isInitialized = true; + + return ResultSuccess{}; +} + +} \ No newline at end of file diff --git a/mesosphere/source/threading/KMutex.cpp b/mesosphere/source/threading/KMutex.cpp index f734ac793..2e8e23735 100644 --- a/mesosphere/source/threading/KMutex.cpp +++ b/mesosphere/source/threading/KMutex.cpp @@ -36,7 +36,7 @@ void KMutex::lock_slow_path(KThread &owner, KThread &requester) void KMutex::unlock_slow_path(KThread &owner) { - KScopedCriticalSection critical_section; + KScopedCriticalSection criticalSection; size_t count; KThread *newOwner = owner.RelinquishMutex(&count, (uiptr)this); native_handle_type newTag; diff --git a/mesosphere/source/threading/KThread.cpp b/mesosphere/source/threading/KThread.cpp index 5811dd995..0869c11de 100644 --- a/mesosphere/source/threading/KThread.cpp +++ b/mesosphere/source/threading/KThread.cpp @@ -46,7 +46,7 @@ void KThread::RescheduleIfStatusEquals(SchedulingStatus expectedStatus, Scheduli void KThread::AddForcePauseReason(KThread::ForcePauseReason reason) { - KScopedCriticalSection critical_section; + KScopedCriticalSection criticalSection; if (!IsDying()) { AddForcePauseReasonToField(reason); @@ -58,7 +58,7 @@ void KThread::AddForcePauseReason(KThread::ForcePauseReason reason) void KThread::RemoveForcePauseReason(KThread::ForcePauseReason reason) { - KScopedCriticalSection critical_section; + KScopedCriticalSection criticalSection; if (!IsDying()) { RemoveForcePauseReasonToField(reason); @@ -104,7 +104,7 @@ void KThread::ResumeAllFromKernelSync(KThread::WaitList &waitList) void KThread::CancelKernelSync() { - KScopedCriticalSection critical_section; + KScopedCriticalSection criticalSection; 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; { - KScopedCriticalSection critical_section; + KScopedCriticalSection criticalSection; // Try to find an already signaled object. if (numSyncObjs >= 1) { @@ -178,7 +178,7 @@ Result KThread::WaitSynchronizationImpl(int &outId, KSynchronizationObject **syn // Now waiting... { - KScopedCriticalSection critical_section; + KScopedCriticalSection criticalSection; isWaitingSync = false; if (timeoutTime > KSystemClock::time_point{}) {