mirror of https://git.suyu.dev/suyu/suyu
Merge pull request #5862 from bunnei/kevent
Kernel Rework: Refactor KEvent/KReadableEvent/KWritableEventmerge-requests/60/head
commit
1498a7c9a8
@ -0,0 +1,32 @@
|
|||||||
|
// Copyright 2021 yuzu emulator team
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include "core/hle/kernel/k_event.h"
|
||||||
|
#include "core/hle/kernel/k_readable_event.h"
|
||||||
|
#include "core/hle/kernel/k_writable_event.h"
|
||||||
|
|
||||||
|
namespace Kernel {
|
||||||
|
|
||||||
|
KEvent::KEvent(KernelCore& kernel, std::string&& name) : Object{kernel, std::move(name)} {}
|
||||||
|
|
||||||
|
KEvent::~KEvent() = default;
|
||||||
|
|
||||||
|
std::shared_ptr<KEvent> KEvent::Create(KernelCore& kernel, std::string&& name) {
|
||||||
|
return std::make_shared<KEvent>(kernel, std::move(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
void KEvent::Initialize() {
|
||||||
|
// Create our sub events.
|
||||||
|
readable_event = std::make_shared<KReadableEvent>(kernel, GetName() + ":Readable");
|
||||||
|
writable_event = std::make_shared<KWritableEvent>(kernel, GetName() + ":Writable");
|
||||||
|
|
||||||
|
// Initialize our sub sessions.
|
||||||
|
readable_event->Initialize(this);
|
||||||
|
writable_event->Initialize(this);
|
||||||
|
|
||||||
|
// Mark initialized.
|
||||||
|
initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Kernel
|
@ -0,0 +1,57 @@
|
|||||||
|
// Copyright 2021 yuzu emulator team
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "core/hle/kernel/object.h"
|
||||||
|
|
||||||
|
namespace Kernel {
|
||||||
|
|
||||||
|
class KernelCore;
|
||||||
|
class KReadableEvent;
|
||||||
|
class KWritableEvent;
|
||||||
|
|
||||||
|
class KEvent final : public Object {
|
||||||
|
public:
|
||||||
|
explicit KEvent(KernelCore& kernel, std::string&& name);
|
||||||
|
~KEvent() override;
|
||||||
|
|
||||||
|
static std::shared_ptr<KEvent> Create(KernelCore& kernel, std::string&& name);
|
||||||
|
|
||||||
|
void Initialize();
|
||||||
|
|
||||||
|
void Finalize() override {}
|
||||||
|
|
||||||
|
std::string GetTypeName() const override {
|
||||||
|
return "KEvent";
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr HandleType HANDLE_TYPE = HandleType::Event;
|
||||||
|
HandleType GetHandleType() const override {
|
||||||
|
return HANDLE_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<KReadableEvent>& GetReadableEvent() {
|
||||||
|
return readable_event;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<KWritableEvent>& GetWritableEvent() {
|
||||||
|
return writable_event;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::shared_ptr<KReadableEvent>& GetReadableEvent() const {
|
||||||
|
return readable_event;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::shared_ptr<KWritableEvent>& GetWritableEvent() const {
|
||||||
|
return writable_event;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::shared_ptr<KReadableEvent> readable_event;
|
||||||
|
std::shared_ptr<KWritableEvent> writable_event;
|
||||||
|
bool initialized{};
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Kernel
|
@ -0,0 +1,57 @@
|
|||||||
|
// Copyright 2021 yuzu emulator team
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include "common/assert.h"
|
||||||
|
#include "common/common_funcs.h"
|
||||||
|
#include "common/logging/log.h"
|
||||||
|
#include "core/hle/kernel/errors.h"
|
||||||
|
#include "core/hle/kernel/k_readable_event.h"
|
||||||
|
#include "core/hle/kernel/k_scheduler.h"
|
||||||
|
#include "core/hle/kernel/k_thread.h"
|
||||||
|
#include "core/hle/kernel/kernel.h"
|
||||||
|
#include "core/hle/kernel/object.h"
|
||||||
|
#include "core/hle/kernel/svc_results.h"
|
||||||
|
|
||||||
|
namespace Kernel {
|
||||||
|
|
||||||
|
KReadableEvent::KReadableEvent(KernelCore& kernel, std::string&& name)
|
||||||
|
: KSynchronizationObject{kernel, std::move(name)} {}
|
||||||
|
KReadableEvent::~KReadableEvent() = default;
|
||||||
|
|
||||||
|
bool KReadableEvent::IsSignaled() const {
|
||||||
|
ASSERT(kernel.GlobalSchedulerContext().IsLocked());
|
||||||
|
|
||||||
|
return is_signaled;
|
||||||
|
}
|
||||||
|
|
||||||
|
ResultCode KReadableEvent::Signal() {
|
||||||
|
KScopedSchedulerLock lk{kernel};
|
||||||
|
|
||||||
|
if (!is_signaled) {
|
||||||
|
is_signaled = true;
|
||||||
|
NotifyAvailable();
|
||||||
|
}
|
||||||
|
|
||||||
|
return RESULT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
ResultCode KReadableEvent::Clear() {
|
||||||
|
Reset();
|
||||||
|
|
||||||
|
return RESULT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
ResultCode KReadableEvent::Reset() {
|
||||||
|
KScopedSchedulerLock lk{kernel};
|
||||||
|
|
||||||
|
if (!is_signaled) {
|
||||||
|
return Svc::ResultInvalidState;
|
||||||
|
}
|
||||||
|
|
||||||
|
is_signaled = false;
|
||||||
|
return RESULT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Kernel
|
@ -0,0 +1,51 @@
|
|||||||
|
// Copyright 2021 yuzu emulator team
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "core/hle/kernel/k_synchronization_object.h"
|
||||||
|
#include "core/hle/kernel/object.h"
|
||||||
|
#include "core/hle/result.h"
|
||||||
|
|
||||||
|
namespace Kernel {
|
||||||
|
|
||||||
|
class KernelCore;
|
||||||
|
class KEvent;
|
||||||
|
|
||||||
|
class KReadableEvent final : public KSynchronizationObject {
|
||||||
|
public:
|
||||||
|
explicit KReadableEvent(KernelCore& kernel, std::string&& name);
|
||||||
|
~KReadableEvent() override;
|
||||||
|
|
||||||
|
std::string GetTypeName() const override {
|
||||||
|
return "KReadableEvent";
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr HandleType HANDLE_TYPE = HandleType::ReadableEvent;
|
||||||
|
HandleType GetHandleType() const override {
|
||||||
|
return HANDLE_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
KEvent* GetParent() const {
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Initialize(KEvent* parent_) {
|
||||||
|
is_signaled = false;
|
||||||
|
parent = parent_;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsSignaled() const override;
|
||||||
|
void Finalize() override {}
|
||||||
|
|
||||||
|
ResultCode Signal();
|
||||||
|
ResultCode Clear();
|
||||||
|
ResultCode Reset();
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool is_signaled{};
|
||||||
|
KEvent* parent{};
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Kernel
|
@ -0,0 +1,27 @@
|
|||||||
|
// Copyright 2021 yuzu emulator team
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include "core/hle/kernel/k_event.h"
|
||||||
|
#include "core/hle/kernel/k_readable_event.h"
|
||||||
|
#include "core/hle/kernel/k_writable_event.h"
|
||||||
|
|
||||||
|
namespace Kernel {
|
||||||
|
|
||||||
|
KWritableEvent::KWritableEvent(KernelCore& kernel, std::string&& name)
|
||||||
|
: Object{kernel, std::move(name)} {}
|
||||||
|
KWritableEvent::~KWritableEvent() = default;
|
||||||
|
|
||||||
|
void KWritableEvent::Initialize(KEvent* parent_) {
|
||||||
|
parent = parent_;
|
||||||
|
}
|
||||||
|
|
||||||
|
ResultCode KWritableEvent::Signal() {
|
||||||
|
return parent->GetReadableEvent()->Signal();
|
||||||
|
}
|
||||||
|
|
||||||
|
ResultCode KWritableEvent::Clear() {
|
||||||
|
return parent->GetReadableEvent()->Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Kernel
|
@ -0,0 +1,44 @@
|
|||||||
|
// Copyright 2021 yuzu Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "core/hle/kernel/object.h"
|
||||||
|
#include "core/hle/result.h"
|
||||||
|
|
||||||
|
namespace Kernel {
|
||||||
|
|
||||||
|
class KernelCore;
|
||||||
|
class KEvent;
|
||||||
|
|
||||||
|
class KWritableEvent final : public Object {
|
||||||
|
public:
|
||||||
|
explicit KWritableEvent(KernelCore& kernel, std::string&& name);
|
||||||
|
~KWritableEvent() override;
|
||||||
|
|
||||||
|
std::string GetTypeName() const override {
|
||||||
|
return "KWritableEvent";
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr HandleType HANDLE_TYPE = HandleType::WritableEvent;
|
||||||
|
HandleType GetHandleType() const override {
|
||||||
|
return HANDLE_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Initialize(KEvent* parent_);
|
||||||
|
|
||||||
|
void Finalize() override {}
|
||||||
|
|
||||||
|
ResultCode Signal();
|
||||||
|
ResultCode Clear();
|
||||||
|
|
||||||
|
KEvent* GetParent() const {
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
KEvent* parent{};
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Kernel
|
@ -1,52 +0,0 @@
|
|||||||
// Copyright 2014 Citra Emulator Project
|
|
||||||
// Licensed under GPLv2 or any later version
|
|
||||||
// Refer to the license.txt file included.
|
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include "common/assert.h"
|
|
||||||
#include "common/logging/log.h"
|
|
||||||
#include "core/hle/kernel/errors.h"
|
|
||||||
#include "core/hle/kernel/k_scheduler.h"
|
|
||||||
#include "core/hle/kernel/k_thread.h"
|
|
||||||
#include "core/hle/kernel/kernel.h"
|
|
||||||
#include "core/hle/kernel/object.h"
|
|
||||||
#include "core/hle/kernel/readable_event.h"
|
|
||||||
|
|
||||||
namespace Kernel {
|
|
||||||
|
|
||||||
ReadableEvent::ReadableEvent(KernelCore& kernel) : KSynchronizationObject{kernel} {}
|
|
||||||
ReadableEvent::~ReadableEvent() = default;
|
|
||||||
|
|
||||||
void ReadableEvent::Signal() {
|
|
||||||
if (is_signaled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
is_signaled = true;
|
|
||||||
NotifyAvailable();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ReadableEvent::IsSignaled() const {
|
|
||||||
ASSERT(kernel.GlobalSchedulerContext().IsLocked());
|
|
||||||
|
|
||||||
return is_signaled;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ReadableEvent::Clear() {
|
|
||||||
is_signaled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ResultCode ReadableEvent::Reset() {
|
|
||||||
KScopedSchedulerLock lock(kernel);
|
|
||||||
if (!is_signaled) {
|
|
||||||
LOG_TRACE(Kernel, "Handle is not signaled! object_id={}, object_type={}, object_name={}",
|
|
||||||
GetObjectId(), GetTypeName(), GetName());
|
|
||||||
return ERR_INVALID_STATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
Clear();
|
|
||||||
|
|
||||||
return RESULT_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Kernel
|
|
@ -1,59 +0,0 @@
|
|||||||
// Copyright 2014 Citra Emulator Project
|
|
||||||
// Licensed under GPLv2 or any later version
|
|
||||||
// Refer to the license.txt file included.
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "core/hle/kernel/k_synchronization_object.h"
|
|
||||||
#include "core/hle/kernel/object.h"
|
|
||||||
|
|
||||||
union ResultCode;
|
|
||||||
|
|
||||||
namespace Kernel {
|
|
||||||
|
|
||||||
class KernelCore;
|
|
||||||
class WritableEvent;
|
|
||||||
|
|
||||||
class ReadableEvent final : public KSynchronizationObject {
|
|
||||||
friend class WritableEvent;
|
|
||||||
|
|
||||||
public:
|
|
||||||
~ReadableEvent() override;
|
|
||||||
|
|
||||||
std::string GetTypeName() const override {
|
|
||||||
return "ReadableEvent";
|
|
||||||
}
|
|
||||||
std::string GetName() const override {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
static constexpr HandleType HANDLE_TYPE = HandleType::ReadableEvent;
|
|
||||||
HandleType GetHandleType() const override {
|
|
||||||
return HANDLE_TYPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Unconditionally clears the readable event's state.
|
|
||||||
void Clear();
|
|
||||||
|
|
||||||
/// Clears the readable event's state if and only if it
|
|
||||||
/// has already been signaled.
|
|
||||||
///
|
|
||||||
/// @pre The event must be in a signaled state. If this event
|
|
||||||
/// is in an unsignaled state and this function is called,
|
|
||||||
/// then ERR_INVALID_STATE will be returned.
|
|
||||||
ResultCode Reset();
|
|
||||||
|
|
||||||
void Signal();
|
|
||||||
|
|
||||||
bool IsSignaled() const override;
|
|
||||||
|
|
||||||
void Finalize() override {}
|
|
||||||
|
|
||||||
private:
|
|
||||||
explicit ReadableEvent(KernelCore& kernel);
|
|
||||||
|
|
||||||
bool is_signaled{};
|
|
||||||
std::string name; ///< Name of event (optional)
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Kernel
|
|
@ -1,41 +0,0 @@
|
|||||||
// Copyright 2014 Citra Emulator Project
|
|
||||||
// Licensed under GPLv2 or any later version
|
|
||||||
// Refer to the license.txt file included.
|
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include "common/assert.h"
|
|
||||||
#include "core/hle/kernel/k_thread.h"
|
|
||||||
#include "core/hle/kernel/kernel.h"
|
|
||||||
#include "core/hle/kernel/object.h"
|
|
||||||
#include "core/hle/kernel/readable_event.h"
|
|
||||||
#include "core/hle/kernel/writable_event.h"
|
|
||||||
|
|
||||||
namespace Kernel {
|
|
||||||
|
|
||||||
WritableEvent::WritableEvent(KernelCore& kernel) : Object{kernel} {}
|
|
||||||
WritableEvent::~WritableEvent() = default;
|
|
||||||
|
|
||||||
EventPair WritableEvent::CreateEventPair(KernelCore& kernel, std::string name) {
|
|
||||||
std::shared_ptr<WritableEvent> writable_event(new WritableEvent(kernel));
|
|
||||||
std::shared_ptr<ReadableEvent> readable_event(new ReadableEvent(kernel));
|
|
||||||
|
|
||||||
writable_event->name = name + ":Writable";
|
|
||||||
writable_event->readable = readable_event;
|
|
||||||
readable_event->name = name + ":Readable";
|
|
||||||
|
|
||||||
return {std::move(readable_event), std::move(writable_event)};
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<ReadableEvent> WritableEvent::GetReadableEvent() const {
|
|
||||||
return readable;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WritableEvent::Signal() {
|
|
||||||
readable->Signal();
|
|
||||||
}
|
|
||||||
|
|
||||||
void WritableEvent::Clear() {
|
|
||||||
readable->Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Kernel
|
|
@ -1,60 +0,0 @@
|
|||||||
// Copyright 2014 Citra Emulator Project
|
|
||||||
// Licensed under GPLv2 or any later version
|
|
||||||
// Refer to the license.txt file included.
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
#include "core/hle/kernel/object.h"
|
|
||||||
|
|
||||||
namespace Kernel {
|
|
||||||
|
|
||||||
class KernelCore;
|
|
||||||
class ReadableEvent;
|
|
||||||
class WritableEvent;
|
|
||||||
|
|
||||||
struct EventPair {
|
|
||||||
std::shared_ptr<ReadableEvent> readable;
|
|
||||||
std::shared_ptr<WritableEvent> writable;
|
|
||||||
};
|
|
||||||
|
|
||||||
class WritableEvent final : public Object {
|
|
||||||
public:
|
|
||||||
~WritableEvent() override;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an event
|
|
||||||
* @param kernel The kernel instance to create this event under.
|
|
||||||
* @param name Optional name of event
|
|
||||||
*/
|
|
||||||
static EventPair CreateEventPair(KernelCore& kernel, std::string name = "Unknown");
|
|
||||||
|
|
||||||
std::string GetTypeName() const override {
|
|
||||||
return "WritableEvent";
|
|
||||||
}
|
|
||||||
std::string GetName() const override {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
static constexpr HandleType HANDLE_TYPE = HandleType::WritableEvent;
|
|
||||||
HandleType GetHandleType() const override {
|
|
||||||
return HANDLE_TYPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<ReadableEvent> GetReadableEvent() const;
|
|
||||||
|
|
||||||
void Signal();
|
|
||||||
void Clear();
|
|
||||||
|
|
||||||
void Finalize() override {}
|
|
||||||
|
|
||||||
private:
|
|
||||||
explicit WritableEvent(KernelCore& kernel);
|
|
||||||
|
|
||||||
std::shared_ptr<ReadableEvent> readable;
|
|
||||||
|
|
||||||
std::string name; ///< Name of event (optional)
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Kernel
|
|
Loading…
Reference in New Issue