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; }
|
||||
|
||||
protected:
|
||||
void SetParent(SharedPtr<Parent> parent)
|
||||
{
|
||||
this->parent = std::move(parent);
|
||||
}
|
||||
|
||||
protected:
|
||||
SharedPtr<Parent> parent{};
|
||||
};
|
||||
|
||||
|
|
|
@ -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{};
|
||||
};
|
||||
|
|
|
@ -21,13 +21,14 @@ class IServer {
|
|||
|
||||
ParentType *GetParent() const { return parent; }
|
||||
|
||||
protected:
|
||||
void SetParent(SharedPtr<Parent> parent)
|
||||
void SetParentAndClient(SharedPtr<Parent> parent, SharedPtr<Client> client)
|
||||
{
|
||||
this->parent = std::move(parent);
|
||||
this->client = &this->parent->client;
|
||||
this->client = std::move(client);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
SharedPtr<Parent> parent{};
|
||||
SharedPtr<Client> client{};
|
||||
};
|
||||
|
|
|
@ -6,6 +6,7 @@ class KProcess;
|
|||
#include <mesosphere/core/Result.hpp>
|
||||
#include <mesosphere/core/KAutoObject.hpp>
|
||||
#include <mesosphere/interfaces/ISetAllocated.hpp>
|
||||
#include <mesosphere/interfaces/ILimitedResource.hpp>
|
||||
#include <mesosphere/interfaces/IClientServerParent.hpp>
|
||||
#include <mesosphere/processes/KReadableEvent.hpp>
|
||||
#include <mesosphere/processes/KWritableEvent.hpp>
|
||||
|
@ -13,26 +14,27 @@ class KProcess;
|
|||
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:
|
||||
MESOSPHERE_AUTO_OBJECT_TRAITS(AutoObject, Event);
|
||||
|
||||
explicit KEvent() : owner(nullptr), is_initialized(false) {}
|
||||
virtual ~KEvent() {}
|
||||
virtual ~KEvent();
|
||||
|
||||
KProcess *GetOwner() const { return this->owner; }
|
||||
void Initialize();
|
||||
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)
|
||||
|
|
|
@ -19,8 +19,7 @@ class KReadableEvent final : public KSynchronizationObject, public IClient<KEven
|
|||
|
||||
virtual bool IsAlive() const override { return true; }
|
||||
|
||||
explicit KReadableEvent() {}
|
||||
virtual ~KReadableEvent() {}
|
||||
virtual ~KReadableEvent();
|
||||
|
||||
Result Signal();
|
||||
Result Clear();
|
||||
|
@ -29,7 +28,7 @@ class KReadableEvent final : public KSynchronizationObject, public IClient<KEven
|
|||
virtual bool IsSignaled() const override;
|
||||
|
||||
private:
|
||||
bool is_signaled = false;
|
||||
bool isSignaled = false;
|
||||
};
|
||||
|
||||
inline void intrusive_ptr_add_ref(KReadableEvent *obj)
|
||||
|
|
|
@ -18,8 +18,7 @@ class KWritableEvent final : public KAutoObject, public IServer<KEvent, KReadabl
|
|||
|
||||
virtual bool IsAlive() const override { return true; }
|
||||
|
||||
explicit KWritableEvent() {}
|
||||
virtual ~KWritableEvent() {}
|
||||
virtual ~KWritableEvent();
|
||||
|
||||
Result Signal();
|
||||
Result Clear();
|
||||
|
|
|
@ -15,7 +15,7 @@ KSynchronizationObject::~KSynchronizationObject()
|
|||
|
||||
void KSynchronizationObject::NotifyWaiters()
|
||||
{
|
||||
KScopedCriticalSection critical_section;
|
||||
KScopedCriticalSection criticalSection;
|
||||
|
||||
if (IsSignaled()) {
|
||||
for (auto &&waiter : waiters) {
|
||||
|
|
|
@ -6,35 +6,43 @@
|
|||
namespace mesosphere
|
||||
{
|
||||
|
||||
bool KReadableEvent::IsSignaled() const {
|
||||
return this->is_signaled;
|
||||
bool KReadableEvent::IsSignaled() const
|
||||
{
|
||||
return this->isSignaled;
|
||||
}
|
||||
|
||||
Result KReadableEvent::Signal() {
|
||||
KScopedCriticalSection critical_section;
|
||||
|
||||
if (!this->is_signaled) {
|
||||
this->is_signaled = true;
|
||||
this->NotifyWaiters();
|
||||
KReadableEvent::~KReadableEvent()
|
||||
{
|
||||
}
|
||||
|
||||
return ResultSuccess();
|
||||
Result KReadableEvent::Signal()
|
||||
{
|
||||
KScopedCriticalSection criticalSection{};
|
||||
|
||||
if (!this->isSignaled) {
|
||||
this->isSignaled = true;
|
||||
NotifyWaiters();
|
||||
}
|
||||
|
||||
Result KReadableEvent::Clear() {
|
||||
this->Reset();
|
||||
|
||||
return ResultSuccess();
|
||||
return ResultSuccess{};
|
||||
}
|
||||
|
||||
Result KReadableEvent::Reset() {
|
||||
KScopedCriticalSection critical_section;
|
||||
Result KReadableEvent::Clear()
|
||||
{
|
||||
Reset();
|
||||
|
||||
if (this->is_signaled) {
|
||||
this->is_signaled = false;
|
||||
return ResultSuccess();
|
||||
return ResultSuccess{};
|
||||
}
|
||||
return ResultKernelInvalidState();
|
||||
|
||||
Result KReadableEvent::Reset()
|
||||
{
|
||||
KScopedCriticalSection criticalSection{};
|
||||
|
||||
if (this->isSignaled) {
|
||||
this->isSignaled = false;
|
||||
return ResultSuccess{};
|
||||
}
|
||||
return ResultKernelInvalidState{};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
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)
|
||||
{
|
||||
KScopedCriticalSection critical_section;
|
||||
KScopedCriticalSection criticalSection;
|
||||
size_t count;
|
||||
KThread *newOwner = owner.RelinquishMutex(&count, (uiptr)this);
|
||||
native_handle_type newTag;
|
||||
|
|
|
@ -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{}) {
|
||||
|
|
Loading…
Reference in a new issue