mesosphere: Skeleton K(Readable/Writable)Event

This commit is contained in:
Michael Scire 2018-11-05 03:51:50 -08:00
parent 600afa5f0f
commit a4419dfc41
7 changed files with 191 additions and 0 deletions

View File

@ -19,6 +19,8 @@ class IClient {
parent->HandleClientDestroyed();
}
ParentType *GetParent() const { return parent; }
protected:
void SetParent(SharedPtr<Parent> parent)
{

View File

@ -18,6 +18,8 @@ class IServer {
{
parent->HandleServerDestroyed();
}
ParentType *GetParent() const { return parent; }
protected:
void SetParent(SharedPtr<Parent> parent)

View File

@ -0,0 +1,48 @@
#pragma once
class KProcess;
#include <mesosphere/core/util.hpp>
#include <mesosphere/core/Result.hpp>
#include <mesosphere/core/KAutoObject.hpp>
#include <mesosphere/interfaces/ISetAllocated.hpp>
#include <mesosphere/interfaces/IClientServerParent.hpp>
#include <mesosphere/processes/KReadableEvent.hpp>
#include <mesosphere/processes/KWritableEvent.hpp>
namespace mesosphere
{
class KEvent final : public KAutoObject, IClientServerParent<KEvent, KReadableEvent, KWritableEvent> {
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);
}
}

View File

@ -0,0 +1,45 @@
#pragma once
#include <mesosphere/core/util.hpp>
#include <mesosphere/core/Result.hpp>
#include <mesosphere/core/KAutoObject.hpp>
#include <mesosphere/core/KSynchronizationObject.hpp>
#include <mesosphere/interfaces/ISetAllocated.hpp>
#include <mesosphere/interfaces/IClient.hpp>
namespace mesosphere
{
class KWritableEvent;
class KEvent;
class KReadableEvent final : public KSynchronizationObject, public IClient<KEvent, KReadableEvent, KWritableEvent> {
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);
}
}

View File

@ -0,0 +1,38 @@
#pragma once
#include <mesosphere/core/util.hpp>
#include <mesosphere/core/Result.hpp>
#include <mesosphere/core/KAutoObject.hpp>
#include <mesosphere/interfaces/ISetAllocated.hpp>
#include <mesosphere/interfaces/IServer.hpp>
namespace mesosphere
{
class KReadableEvent;
class KEvent;
class KWritableEvent final : public KAutoObject, public IServer<KEvent, KReadableEvent, KWritableEvent> {
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);
}
}

View File

@ -0,0 +1,40 @@
#include <mesosphere/processes/KWritableEvent.hpp>
#include <mesosphere/processes/KReadableEvent.hpp>
#include <mesosphere/processes/KEvent.hpp>
#include <mesosphere/threading/KScheduler.hpp>
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();
}
}

View File

@ -0,0 +1,16 @@
#include <mesosphere/processes/KWritableEvent.hpp>
#include <mesosphere/processes/KReadableEvent.hpp>
#include <mesosphere/processes/KEvent.hpp>
namespace mesosphere
{
Result KWritableEvent::Signal() {
return this->client->Signal();
}
Result KWritableEvent::Clear() {
return this->client->Clear();
}
}