mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2025-01-03 11:11:14 +00:00
Write KEvent::Initialize, fix build issues
This commit is contained in:
parent
a4419dfc41
commit
698fa9fcb0
12 changed files with 100 additions and 58 deletions
|
@ -21,12 +21,12 @@ class IClient {
|
||||||
|
|
||||||
ParentType *GetParent() const { return parent; }
|
ParentType *GetParent() const { return parent; }
|
||||||
|
|
||||||
protected:
|
|
||||||
void SetParent(SharedPtr<Parent> parent)
|
void SetParent(SharedPtr<Parent> parent)
|
||||||
{
|
{
|
||||||
this->parent = std::move(parent);
|
this->parent = std::move(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
SharedPtr<Parent> parent{};
|
SharedPtr<Parent> parent{};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -12,14 +12,15 @@ class IClientServerParent {
|
||||||
using ClientType = Client;
|
using ClientType = Client;
|
||||||
using ServerType = Server;
|
using ServerType = Server;
|
||||||
|
|
||||||
protected:
|
|
||||||
void SetClientServerParent()
|
void SetClientServerParent()
|
||||||
{
|
{
|
||||||
Parent par = (Parent *)this;
|
Parent *par = (Parent *)this;
|
||||||
client.SetParent(par);
|
client.SetParent(par);
|
||||||
server.SetParent(par);
|
server.SetParentAndClient(par, &client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
ClientType client{};
|
ClientType client{};
|
||||||
ServerType server{};
|
ServerType server{};
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,13 +21,14 @@ class IServer {
|
||||||
|
|
||||||
ParentType *GetParent() const { return parent; }
|
ParentType *GetParent() const { return parent; }
|
||||||
|
|
||||||
protected:
|
void SetParentAndClient(SharedPtr<Parent> parent, SharedPtr<Client> client)
|
||||||
void SetParent(SharedPtr<Parent> parent)
|
|
||||||
{
|
{
|
||||||
this->parent = std::move(parent);
|
this->parent = std::move(parent);
|
||||||
this->client = &this->parent->client;
|
this->client = std::move(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
SharedPtr<Parent> parent{};
|
SharedPtr<Parent> parent{};
|
||||||
SharedPtr<Client> client{};
|
SharedPtr<Client> client{};
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,6 +6,7 @@ class KProcess;
|
||||||
#include <mesosphere/core/Result.hpp>
|
#include <mesosphere/core/Result.hpp>
|
||||||
#include <mesosphere/core/KAutoObject.hpp>
|
#include <mesosphere/core/KAutoObject.hpp>
|
||||||
#include <mesosphere/interfaces/ISetAllocated.hpp>
|
#include <mesosphere/interfaces/ISetAllocated.hpp>
|
||||||
|
#include <mesosphere/interfaces/ILimitedResource.hpp>
|
||||||
#include <mesosphere/interfaces/IClientServerParent.hpp>
|
#include <mesosphere/interfaces/IClientServerParent.hpp>
|
||||||
#include <mesosphere/processes/KReadableEvent.hpp>
|
#include <mesosphere/processes/KReadableEvent.hpp>
|
||||||
#include <mesosphere/processes/KWritableEvent.hpp>
|
#include <mesosphere/processes/KWritableEvent.hpp>
|
||||||
|
@ -13,26 +14,27 @@ class KProcess;
|
||||||
namespace mesosphere
|
namespace mesosphere
|
||||||
{
|
{
|
||||||
|
|
||||||
class KEvent final : public KAutoObject, IClientServerParent<KEvent, KReadableEvent, KWritableEvent> {
|
class KEvent final :
|
||||||
|
public KAutoObject,
|
||||||
|
public IClientServerParent<KEvent, KReadableEvent, KWritableEvent>,
|
||||||
|
public ISetAllocated<KEvent>,
|
||||||
|
public ILimitedResource<KEvent> {
|
||||||
public:
|
public:
|
||||||
MESOSPHERE_AUTO_OBJECT_TRAITS(AutoObject, Event);
|
MESOSPHERE_AUTO_OBJECT_TRAITS(AutoObject, Event);
|
||||||
|
|
||||||
explicit KEvent() : owner(nullptr), is_initialized(false) {}
|
virtual ~KEvent();
|
||||||
virtual ~KEvent() {}
|
|
||||||
|
Result Initialize();
|
||||||
KProcess *GetOwner() const { return this->owner; }
|
|
||||||
void Initialize();
|
|
||||||
|
|
||||||
/* KAutoObject */
|
/* KAutoObject */
|
||||||
virtual bool IsAlive() const override { return is_initialized; }
|
virtual bool IsAlive() const override;
|
||||||
|
|
||||||
/* IClientServerParent */
|
/* IClientServerParent */
|
||||||
void HandleServerDestroyed() { }
|
void HandleServerDestroyed() { }
|
||||||
void HandleClientDestroyed() { }
|
void HandleClientDestroyed() { }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KProcess *owner;
|
bool isInitialized = false;
|
||||||
bool is_initialized;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void intrusive_ptr_add_ref(KEvent *obj)
|
inline void intrusive_ptr_add_ref(KEvent *obj)
|
||||||
|
|
|
@ -16,20 +16,19 @@ class KEvent;
|
||||||
class KReadableEvent final : public KSynchronizationObject, public IClient<KEvent, KReadableEvent, KWritableEvent> {
|
class KReadableEvent final : public KSynchronizationObject, public IClient<KEvent, KReadableEvent, KWritableEvent> {
|
||||||
public:
|
public:
|
||||||
MESOSPHERE_AUTO_OBJECT_TRAITS(SynchronizationObject, ReadableEvent);
|
MESOSPHERE_AUTO_OBJECT_TRAITS(SynchronizationObject, ReadableEvent);
|
||||||
|
|
||||||
virtual bool IsAlive() const override { return true; }
|
virtual bool IsAlive() const override { return true; }
|
||||||
|
|
||||||
explicit KReadableEvent() {}
|
virtual ~KReadableEvent();
|
||||||
virtual ~KReadableEvent() {}
|
|
||||||
|
|
||||||
Result Signal();
|
Result Signal();
|
||||||
Result Clear();
|
Result Clear();
|
||||||
Result Reset();
|
Result Reset();
|
||||||
|
|
||||||
virtual bool IsSignaled() const override;
|
virtual bool IsSignaled() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool is_signaled = false;
|
bool isSignaled = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void intrusive_ptr_add_ref(KReadableEvent *obj)
|
inline void intrusive_ptr_add_ref(KReadableEvent *obj)
|
||||||
|
|
|
@ -17,9 +17,8 @@ class KWritableEvent final : public KAutoObject, public IServer<KEvent, KReadabl
|
||||||
MESOSPHERE_AUTO_OBJECT_TRAITS(AutoObject, WritableEvent);
|
MESOSPHERE_AUTO_OBJECT_TRAITS(AutoObject, WritableEvent);
|
||||||
|
|
||||||
virtual bool IsAlive() const override { return true; }
|
virtual bool IsAlive() const override { return true; }
|
||||||
|
|
||||||
explicit KWritableEvent() {}
|
virtual ~KWritableEvent();
|
||||||
virtual ~KWritableEvent() {}
|
|
||||||
|
|
||||||
Result Signal();
|
Result Signal();
|
||||||
Result Clear();
|
Result Clear();
|
||||||
|
|
|
@ -15,7 +15,7 @@ KSynchronizationObject::~KSynchronizationObject()
|
||||||
|
|
||||||
void KSynchronizationObject::NotifyWaiters()
|
void KSynchronizationObject::NotifyWaiters()
|
||||||
{
|
{
|
||||||
KScopedCriticalSection critical_section;
|
KScopedCriticalSection criticalSection;
|
||||||
|
|
||||||
if (IsSignaled()) {
|
if (IsSignaled()) {
|
||||||
for (auto &&waiter : waiters) {
|
for (auto &&waiter : waiters) {
|
||||||
|
|
|
@ -5,36 +5,44 @@
|
||||||
|
|
||||||
namespace mesosphere
|
namespace mesosphere
|
||||||
{
|
{
|
||||||
|
|
||||||
bool KReadableEvent::IsSignaled() const {
|
bool KReadableEvent::IsSignaled() const
|
||||||
return this->is_signaled;
|
{
|
||||||
|
return this->isSignaled;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result KReadableEvent::Signal() {
|
KReadableEvent::~KReadableEvent()
|
||||||
KScopedCriticalSection critical_section;
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Result KReadableEvent::Signal()
|
||||||
|
{
|
||||||
|
KScopedCriticalSection criticalSection{};
|
||||||
|
|
||||||
if (!this->is_signaled) {
|
if (!this->isSignaled) {
|
||||||
this->is_signaled = true;
|
this->isSignaled = true;
|
||||||
this->NotifyWaiters();
|
NotifyWaiters();
|
||||||
}
|
}
|
||||||
|
|
||||||
return ResultSuccess();
|
return ResultSuccess{};
|
||||||
}
|
}
|
||||||
|
|
||||||
Result KReadableEvent::Clear() {
|
Result KReadableEvent::Clear()
|
||||||
this->Reset();
|
{
|
||||||
|
Reset();
|
||||||
return ResultSuccess();
|
|
||||||
|
return ResultSuccess{};
|
||||||
}
|
}
|
||||||
|
|
||||||
Result KReadableEvent::Reset() {
|
Result KReadableEvent::Reset()
|
||||||
KScopedCriticalSection critical_section;
|
{
|
||||||
|
KScopedCriticalSection criticalSection{};
|
||||||
if (this->is_signaled) {
|
|
||||||
this->is_signaled = false;
|
if (this->isSignaled) {
|
||||||
return ResultSuccess();
|
this->isSignaled = false;
|
||||||
|
return ResultSuccess{};
|
||||||
}
|
}
|
||||||
return ResultKernelInvalidState();
|
return ResultKernelInvalidState{};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,12 +5,18 @@
|
||||||
namespace mesosphere
|
namespace mesosphere
|
||||||
{
|
{
|
||||||
|
|
||||||
Result KWritableEvent::Signal() {
|
KWritableEvent::~KWritableEvent()
|
||||||
return this->client->Signal();
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Result KWritableEvent::Clear() {
|
Result KWritableEvent::Signal()
|
||||||
return this->client->Clear();
|
{
|
||||||
|
return client->Signal();
|
||||||
|
}
|
||||||
|
|
||||||
|
Result KWritableEvent::Clear()
|
||||||
|
{
|
||||||
|
return client->Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
26
mesosphere/source/threading/KEvent.cpp
Normal file
26
mesosphere/source/threading/KEvent.cpp
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
#include <mesosphere/processes/KEvent.hpp>
|
||||||
|
#include <mesosphere/core/KCoreContext.hpp>
|
||||||
|
#include <mesosphere/processes/KProcess.hpp>
|
||||||
|
|
||||||
|
namespace mesosphere
|
||||||
|
{
|
||||||
|
|
||||||
|
KEvent::~KEvent()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool KEvent::IsAlive() const
|
||||||
|
{
|
||||||
|
return isInitialized;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result KEvent::Initialize()
|
||||||
|
{
|
||||||
|
SetClientServerParent();
|
||||||
|
SetResourceOwner(KCoreContext::GetCurrentInstance().GetCurrentProcess());
|
||||||
|
isInitialized = true;
|
||||||
|
|
||||||
|
return ResultSuccess{};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -36,7 +36,7 @@ void KMutex::lock_slow_path(KThread &owner, KThread &requester)
|
||||||
|
|
||||||
void KMutex::unlock_slow_path(KThread &owner)
|
void KMutex::unlock_slow_path(KThread &owner)
|
||||||
{
|
{
|
||||||
KScopedCriticalSection critical_section;
|
KScopedCriticalSection criticalSection;
|
||||||
size_t count;
|
size_t count;
|
||||||
KThread *newOwner = owner.RelinquishMutex(&count, (uiptr)this);
|
KThread *newOwner = owner.RelinquishMutex(&count, (uiptr)this);
|
||||||
native_handle_type newTag;
|
native_handle_type newTag;
|
||||||
|
|
|
@ -46,7 +46,7 @@ void KThread::RescheduleIfStatusEquals(SchedulingStatus expectedStatus, Scheduli
|
||||||
|
|
||||||
void KThread::AddForcePauseReason(KThread::ForcePauseReason reason)
|
void KThread::AddForcePauseReason(KThread::ForcePauseReason reason)
|
||||||
{
|
{
|
||||||
KScopedCriticalSection critical_section;
|
KScopedCriticalSection criticalSection;
|
||||||
|
|
||||||
if (!IsDying()) {
|
if (!IsDying()) {
|
||||||
AddForcePauseReasonToField(reason);
|
AddForcePauseReasonToField(reason);
|
||||||
|
@ -58,7 +58,7 @@ void KThread::AddForcePauseReason(KThread::ForcePauseReason reason)
|
||||||
|
|
||||||
void KThread::RemoveForcePauseReason(KThread::ForcePauseReason reason)
|
void KThread::RemoveForcePauseReason(KThread::ForcePauseReason reason)
|
||||||
{
|
{
|
||||||
KScopedCriticalSection critical_section;
|
KScopedCriticalSection criticalSection;
|
||||||
|
|
||||||
if (!IsDying()) {
|
if (!IsDying()) {
|
||||||
RemoveForcePauseReasonToField(reason);
|
RemoveForcePauseReasonToField(reason);
|
||||||
|
@ -104,7 +104,7 @@ void KThread::ResumeAllFromKernelSync(KThread::WaitList &waitList)
|
||||||
|
|
||||||
void KThread::CancelKernelSync()
|
void KThread::CancelKernelSync()
|
||||||
{
|
{
|
||||||
KScopedCriticalSection critical_section;
|
KScopedCriticalSection criticalSection;
|
||||||
if (GetSchedulingStatus() == SchedulingStatus::Paused) {
|
if (GetSchedulingStatus() == SchedulingStatus::Paused) {
|
||||||
// Note: transparent to force-pause
|
// Note: transparent to force-pause
|
||||||
if (currentWaitList != nullptr) {
|
if (currentWaitList != nullptr) {
|
||||||
|
@ -136,7 +136,7 @@ Result KThread::WaitSynchronizationImpl(int &outId, KSynchronizationObject **syn
|
||||||
|
|
||||||
outId = -1;
|
outId = -1;
|
||||||
{
|
{
|
||||||
KScopedCriticalSection critical_section;
|
KScopedCriticalSection criticalSection;
|
||||||
|
|
||||||
// Try to find an already signaled object.
|
// Try to find an already signaled object.
|
||||||
if (numSyncObjs >= 1) {
|
if (numSyncObjs >= 1) {
|
||||||
|
@ -178,7 +178,7 @@ Result KThread::WaitSynchronizationImpl(int &outId, KSynchronizationObject **syn
|
||||||
// Now waiting...
|
// Now waiting...
|
||||||
|
|
||||||
{
|
{
|
||||||
KScopedCriticalSection critical_section;
|
KScopedCriticalSection criticalSection;
|
||||||
|
|
||||||
isWaitingSync = false;
|
isWaitingSync = false;
|
||||||
if (timeoutTime > KSystemClock::time_point{}) {
|
if (timeoutTime > KSystemClock::time_point{}) {
|
||||||
|
|
Loading…
Reference in a new issue