mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-30 18:34:38 +01:00
mesosphere: Skeleton K(Readable/Writable)Event
This commit is contained in:
parent
600afa5f0f
commit
a4419dfc41
@ -19,6 +19,8 @@ class IClient {
|
||||
parent->HandleClientDestroyed();
|
||||
}
|
||||
|
||||
ParentType *GetParent() const { return parent; }
|
||||
|
||||
protected:
|
||||
void SetParent(SharedPtr<Parent> parent)
|
||||
{
|
||||
|
@ -18,6 +18,8 @@ class IServer {
|
||||
{
|
||||
parent->HandleServerDestroyed();
|
||||
}
|
||||
|
||||
ParentType *GetParent() const { return parent; }
|
||||
|
||||
protected:
|
||||
void SetParent(SharedPtr<Parent> parent)
|
||||
|
48
mesosphere/include/mesosphere/processes/KEvent.hpp
Normal file
48
mesosphere/include/mesosphere/processes/KEvent.hpp
Normal 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);
|
||||
}
|
||||
|
||||
}
|
45
mesosphere/include/mesosphere/processes/KReadableEvent.hpp
Normal file
45
mesosphere/include/mesosphere/processes/KReadableEvent.hpp
Normal 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);
|
||||
}
|
||||
|
||||
}
|
38
mesosphere/include/mesosphere/processes/KWritableEvent.hpp
Normal file
38
mesosphere/include/mesosphere/processes/KWritableEvent.hpp
Normal 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);
|
||||
}
|
||||
|
||||
}
|
40
mesosphere/source/processes/KReadableEvent.cpp
Normal file
40
mesosphere/source/processes/KReadableEvent.cpp
Normal 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();
|
||||
}
|
||||
|
||||
}
|
16
mesosphere/source/processes/KWritableEvent.cpp
Normal file
16
mesosphere/source/processes/KWritableEvent.cpp
Normal 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();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user