From a4419dfc4106bb31e50a1e34e647f3016a069fed Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Mon, 5 Nov 2018 03:51:50 -0800 Subject: [PATCH] mesosphere: Skeleton K(Readable/Writable)Event --- .../include/mesosphere/interfaces/IClient.hpp | 2 + .../include/mesosphere/interfaces/IServer.hpp | 2 + .../include/mesosphere/processes/KEvent.hpp | 48 +++++++++++++++++++ .../mesosphere/processes/KReadableEvent.hpp | 45 +++++++++++++++++ .../mesosphere/processes/KWritableEvent.hpp | 38 +++++++++++++++ .../source/processes/KReadableEvent.cpp | 40 ++++++++++++++++ .../source/processes/KWritableEvent.cpp | 16 +++++++ 7 files changed, 191 insertions(+) create mode 100644 mesosphere/include/mesosphere/processes/KEvent.hpp create mode 100644 mesosphere/include/mesosphere/processes/KReadableEvent.hpp create mode 100644 mesosphere/include/mesosphere/processes/KWritableEvent.hpp create mode 100644 mesosphere/source/processes/KReadableEvent.cpp create mode 100644 mesosphere/source/processes/KWritableEvent.cpp diff --git a/mesosphere/include/mesosphere/interfaces/IClient.hpp b/mesosphere/include/mesosphere/interfaces/IClient.hpp index 28a165220..31610ecdd 100644 --- a/mesosphere/include/mesosphere/interfaces/IClient.hpp +++ b/mesosphere/include/mesosphere/interfaces/IClient.hpp @@ -19,6 +19,8 @@ class IClient { parent->HandleClientDestroyed(); } + ParentType *GetParent() const { return parent; } + protected: void SetParent(SharedPtr parent) { diff --git a/mesosphere/include/mesosphere/interfaces/IServer.hpp b/mesosphere/include/mesosphere/interfaces/IServer.hpp index 326f718cf..d2d9fc00e 100644 --- a/mesosphere/include/mesosphere/interfaces/IServer.hpp +++ b/mesosphere/include/mesosphere/interfaces/IServer.hpp @@ -18,6 +18,8 @@ class IServer { { parent->HandleServerDestroyed(); } + + ParentType *GetParent() const { return parent; } protected: void SetParent(SharedPtr parent) diff --git a/mesosphere/include/mesosphere/processes/KEvent.hpp b/mesosphere/include/mesosphere/processes/KEvent.hpp new file mode 100644 index 000000000..24e49c2e7 --- /dev/null +++ b/mesosphere/include/mesosphere/processes/KEvent.hpp @@ -0,0 +1,48 @@ +#pragma once + +class KProcess; + +#include +#include +#include +#include +#include +#include +#include + +namespace mesosphere +{ + +class KEvent final : public KAutoObject, IClientServerParent { + public: + MESOSPHERE_AUTO_OBJECT_TRAITS(AutoObject, Event); + + explicit KEvent() : owner(nullptr), is_initialized(false) {} + virtual ~KEvent() {} + + KProcess *GetOwner() const { return this->owner; } + void Initialize(); + + /* KAutoObject */ + virtual bool IsAlive() const override { return is_initialized; } + + /* IClientServerParent */ + void HandleServerDestroyed() { } + void HandleClientDestroyed() { } + + private: + KProcess *owner; + bool is_initialized; +}; + +inline void intrusive_ptr_add_ref(KEvent *obj) +{ + intrusive_ptr_add_ref((KAutoObject *)obj); +} + +inline void intrusive_ptr_release(KEvent *obj) +{ + intrusive_ptr_release((KAutoObject *)obj); +} + +} diff --git a/mesosphere/include/mesosphere/processes/KReadableEvent.hpp b/mesosphere/include/mesosphere/processes/KReadableEvent.hpp new file mode 100644 index 000000000..912602b84 --- /dev/null +++ b/mesosphere/include/mesosphere/processes/KReadableEvent.hpp @@ -0,0 +1,45 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + +namespace mesosphere +{ + +class KWritableEvent; +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() {} + + Result Signal(); + Result Clear(); + Result Reset(); + + virtual bool IsSignaled() const override; + + private: + bool is_signaled = false; +}; + +inline void intrusive_ptr_add_ref(KReadableEvent *obj) +{ + intrusive_ptr_add_ref((KAutoObject *)obj); +} + +inline void intrusive_ptr_release(KReadableEvent *obj) +{ + intrusive_ptr_release((KAutoObject *)obj); +} + +} diff --git a/mesosphere/include/mesosphere/processes/KWritableEvent.hpp b/mesosphere/include/mesosphere/processes/KWritableEvent.hpp new file mode 100644 index 000000000..2a92fee77 --- /dev/null +++ b/mesosphere/include/mesosphere/processes/KWritableEvent.hpp @@ -0,0 +1,38 @@ +#pragma once + +#include +#include +#include +#include +#include + +namespace mesosphere +{ + +class KReadableEvent; +class KEvent; + +class KWritableEvent final : public KAutoObject, public IServer { + public: + MESOSPHERE_AUTO_OBJECT_TRAITS(AutoObject, WritableEvent); + + virtual bool IsAlive() const override { return true; } + + explicit KWritableEvent() {} + virtual ~KWritableEvent() {} + + Result Signal(); + Result Clear(); +}; + +inline void intrusive_ptr_add_ref(KWritableEvent *obj) +{ + intrusive_ptr_add_ref((KAutoObject *)obj); +} + +inline void intrusive_ptr_release(KWritableEvent *obj) +{ + intrusive_ptr_release((KAutoObject *)obj); +} + +} diff --git a/mesosphere/source/processes/KReadableEvent.cpp b/mesosphere/source/processes/KReadableEvent.cpp new file mode 100644 index 000000000..09c8a3cee --- /dev/null +++ b/mesosphere/source/processes/KReadableEvent.cpp @@ -0,0 +1,40 @@ +#include +#include +#include +#include + +namespace mesosphere +{ + +bool KReadableEvent::IsSignaled() const { + return this->is_signaled; +} + +Result KReadableEvent::Signal() { + KScopedCriticalSection critical_section; + + if (!this->is_signaled) { + this->is_signaled = true; + this->NotifyWaiters(); + } + + return ResultSuccess(); +} + +Result KReadableEvent::Clear() { + this->Reset(); + + return ResultSuccess(); +} + +Result KReadableEvent::Reset() { + KScopedCriticalSection critical_section; + + if (this->is_signaled) { + this->is_signaled = false; + return ResultSuccess(); + } + return ResultKernelInvalidState(); +} + +} diff --git a/mesosphere/source/processes/KWritableEvent.cpp b/mesosphere/source/processes/KWritableEvent.cpp new file mode 100644 index 000000000..c36690fae --- /dev/null +++ b/mesosphere/source/processes/KWritableEvent.cpp @@ -0,0 +1,16 @@ +#include +#include +#include + +namespace mesosphere +{ + +Result KWritableEvent::Signal() { + return this->client->Signal(); +} + +Result KWritableEvent::Clear() { + return this->client->Clear(); +} + +}