summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle/kernel')
-rw-r--r--src/core/hle/kernel/hle_ipc.cpp29
-rw-r--r--src/core/hle/kernel/hle_ipc.h12
-rw-r--r--src/core/hle/kernel/object.h6
-rw-r--r--src/core/hle/kernel/readable_event.cpp (renamed from src/core/hle/kernel/event.cpp)27
-rw-r--r--src/core/hle/kernel/readable_event.h55
-rw-r--r--src/core/hle/kernel/svc.cpp7
-rw-r--r--src/core/hle/kernel/writable_event.cpp52
-rw-r--r--src/core/hle/kernel/writable_event.h (renamed from src/core/hle/kernel/event.h)33
8 files changed, 163 insertions, 58 deletions
diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp
index 68d5376cb..61ce7d7e4 100644
--- a/src/core/hle/kernel/hle_ipc.cpp
+++ b/src/core/hle/kernel/hle_ipc.cpp
@@ -15,13 +15,14 @@
#include "common/logging/log.h"
#include "core/core.h"
#include "core/hle/ipc_helpers.h"
-#include "core/hle/kernel/event.h"
#include "core/hle/kernel/handle_table.h"
#include "core/hle/kernel/hle_ipc.h"
#include "core/hle/kernel/kernel.h"
#include "core/hle/kernel/object.h"
#include "core/hle/kernel/process.h"
+#include "core/hle/kernel/readable_event.h"
#include "core/hle/kernel/server_session.h"
+#include "core/hle/kernel/writable_event.h"
#include "core/memory.h"
namespace Kernel {
@@ -36,11 +37,9 @@ void SessionRequestHandler::ClientDisconnected(const SharedPtr<ServerSession>& s
boost::range::remove_erase(connected_sessions, server_session);
}
-SharedPtr<Event> HLERequestContext::SleepClientThread(SharedPtr<Thread> thread,
- const std::string& reason, u64 timeout,
- WakeupCallback&& callback,
- Kernel::SharedPtr<Kernel::Event> event) {
-
+SharedPtr<WritableEvent> HLERequestContext::SleepClientThread(
+ SharedPtr<Thread> thread, const std::string& reason, u64 timeout, WakeupCallback&& callback,
+ SharedPtr<WritableEvent> writable_event) {
// Put the client thread to sleep until the wait event is signaled or the timeout expires.
thread->SetWakeupCallback([context = *this, callback](
ThreadWakeupReason reason, SharedPtr<Thread> thread,
@@ -51,23 +50,25 @@ SharedPtr<Event> HLERequestContext::SleepClientThread(SharedPtr<Thread> thread,
return true;
});
- if (!event) {
+ auto& kernel = Core::System::GetInstance().Kernel();
+ if (!writable_event) {
// Create event if not provided
- auto& kernel = Core::System::GetInstance().Kernel();
- event =
- Kernel::Event::Create(kernel, Kernel::ResetType::OneShot, "HLE Pause Event: " + reason);
+ const auto pair = WritableEvent::CreateEventPair(kernel, Kernel::ResetType::OneShot,
+ "HLE Pause Event: " + reason);
+ writable_event = pair.writable;
}
- event->Clear();
+ const auto readable_event{writable_event->GetReadableEvent()};
+ writable_event->Clear();
thread->SetStatus(ThreadStatus::WaitHLEEvent);
- thread->SetWaitObjects({event});
- event->AddWaitingThread(thread);
+ thread->SetWaitObjects({readable_event});
+ readable_event->AddWaitingThread(thread);
if (timeout > 0) {
thread->WakeAfterDelay(timeout);
}
- return event;
+ return writable_event;
}
HLERequestContext::HLERequestContext(SharedPtr<Kernel::ServerSession> server_session)
diff --git a/src/core/hle/kernel/hle_ipc.h b/src/core/hle/kernel/hle_ipc.h
index a38e34b74..e5c0610cd 100644
--- a/src/core/hle/kernel/hle_ipc.h
+++ b/src/core/hle/kernel/hle_ipc.h
@@ -24,10 +24,11 @@ class ServiceFrameworkBase;
namespace Kernel {
class Domain;
-class Event;
class HandleTable;
class HLERequestContext;
class Process;
+class ReadableEvent;
+class WritableEvent;
/**
* Interface implemented by HLE Session handlers.
@@ -119,12 +120,13 @@ public:
* @param callback Callback to be invoked when the thread is resumed. This callback must write
* the entire command response once again, regardless of the state of it before this function
* was called.
- * @param event Event to use to wake up the thread. If unspecified, an event will be created.
+ * @param writable_event Event to use to wake up the thread. If unspecified, an event will be
+ * created.
* @returns Event that when signaled will resume the thread and call the callback function.
*/
- SharedPtr<Event> SleepClientThread(SharedPtr<Thread> thread, const std::string& reason,
- u64 timeout, WakeupCallback&& callback,
- Kernel::SharedPtr<Kernel::Event> event = nullptr);
+ SharedPtr<WritableEvent> SleepClientThread(SharedPtr<Thread> thread, const std::string& reason,
+ u64 timeout, WakeupCallback&& callback,
+ SharedPtr<WritableEvent> writable_event = nullptr);
/// Populates this context with data from the requesting process/thread.
ResultCode PopulateFromIncomingCommandBuffer(const HandleTable& handle_table,
diff --git a/src/core/hle/kernel/object.h b/src/core/hle/kernel/object.h
index c9f4d0bb3..69082ce3e 100644
--- a/src/core/hle/kernel/object.h
+++ b/src/core/hle/kernel/object.h
@@ -33,9 +33,9 @@ enum class HandleType : u32 {
};
enum class ResetType {
- OneShot,
- Sticky,
- Pulse,
+ OneShot, ///< Reset automatically on object acquisition
+ Sticky, ///< Never reset automatically
+ Pulse, ///< Reset automatically on wakeup
};
class Object : NonCopyable {
diff --git a/src/core/hle/kernel/event.cpp b/src/core/hle/kernel/readable_event.cpp
index 8967e602e..92e16b4e6 100644
--- a/src/core/hle/kernel/event.cpp
+++ b/src/core/hle/kernel/readable_event.cpp
@@ -4,46 +4,37 @@
#include <algorithm>
#include "common/assert.h"
-#include "core/hle/kernel/event.h"
#include "core/hle/kernel/object.h"
+#include "core/hle/kernel/readable_event.h"
#include "core/hle/kernel/thread.h"
+#include "core/hle/kernel/writable_event.h"
namespace Kernel {
-Event::Event(KernelCore& kernel) : WaitObject{kernel} {}
-Event::~Event() = default;
+ReadableEvent::ReadableEvent(KernelCore& kernel) : WaitObject{kernel} {}
+ReadableEvent::~ReadableEvent() = default;
-SharedPtr<Event> Event::Create(KernelCore& kernel, ResetType reset_type, std::string name) {
- SharedPtr<Event> evt(new Event(kernel));
-
- evt->signaled = false;
- evt->reset_type = reset_type;
- evt->name = std::move(name);
-
- return evt;
-}
-
-bool Event::ShouldWait(Thread* thread) const {
+bool ReadableEvent::ShouldWait(Thread* thread) const {
return !signaled;
}
-void Event::Acquire(Thread* thread) {
+void ReadableEvent::Acquire(Thread* thread) {
ASSERT_MSG(!ShouldWait(thread), "object unavailable!");
if (reset_type == ResetType::OneShot)
signaled = false;
}
-void Event::Signal() {
+void ReadableEvent::Signal() {
signaled = true;
WakeupAllWaitingThreads();
}
-void Event::Clear() {
+void ReadableEvent::Clear() {
signaled = false;
}
-void Event::WakeupAllWaitingThreads() {
+void ReadableEvent::WakeupAllWaitingThreads() {
WaitObject::WakeupAllWaitingThreads();
if (reset_type == ResetType::Pulse)
diff --git a/src/core/hle/kernel/readable_event.h b/src/core/hle/kernel/readable_event.h
new file mode 100644
index 000000000..b1f1f4871
--- /dev/null
+++ b/src/core/hle/kernel/readable_event.h
@@ -0,0 +1,55 @@
+// 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/object.h"
+#include "core/hle/kernel/wait_object.h"
+
+namespace Kernel {
+
+class KernelCore;
+class WritableEvent;
+
+class ReadableEvent final : public WaitObject {
+ friend class WritableEvent;
+
+public:
+ ~ReadableEvent() override;
+
+ std::string GetTypeName() const override {
+ return "ReadableEvent";
+ }
+ std::string GetName() const override {
+ return name;
+ }
+
+ ResetType GetResetType() const {
+ return reset_type;
+ }
+
+ static const HandleType HANDLE_TYPE = HandleType::Event;
+ HandleType GetHandleType() const override {
+ return HANDLE_TYPE;
+ }
+
+ bool ShouldWait(Thread* thread) const override;
+ void Acquire(Thread* thread) override;
+
+ void WakeupAllWaitingThreads() override;
+
+ void Clear();
+
+private:
+ explicit ReadableEvent(KernelCore& kernel);
+
+ void Signal();
+
+ ResetType reset_type;
+ bool signaled;
+
+ std::string name; ///< Name of event (optional)
+};
+
+} // namespace Kernel
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index aafd16800..e86d60c22 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -20,17 +20,18 @@
#include "core/hle/kernel/address_arbiter.h"
#include "core/hle/kernel/client_port.h"
#include "core/hle/kernel/client_session.h"
-#include "core/hle/kernel/event.h"
#include "core/hle/kernel/handle_table.h"
#include "core/hle/kernel/kernel.h"
#include "core/hle/kernel/mutex.h"
#include "core/hle/kernel/process.h"
+#include "core/hle/kernel/readable_event.h"
#include "core/hle/kernel/resource_limit.h"
#include "core/hle/kernel/scheduler.h"
#include "core/hle/kernel/shared_memory.h"
#include "core/hle/kernel/svc.h"
#include "core/hle/kernel/svc_wrap.h"
#include "core/hle/kernel/thread.h"
+#include "core/hle/kernel/writable_event.h"
#include "core/hle/lock.h"
#include "core/hle/result.h"
#include "core/hle/service/service.h"
@@ -1411,7 +1412,7 @@ static ResultCode ResetSignal(Handle handle) {
LOG_DEBUG(Kernel_SVC, "called handle 0x{:08X}", handle);
const auto& handle_table = Core::CurrentProcess()->GetHandleTable();
- auto event = handle_table.Get<Event>(handle);
+ auto event = handle_table.Get<ReadableEvent>(handle);
ASSERT(event != nullptr);
@@ -1574,7 +1575,7 @@ static ResultCode ClearEvent(Handle handle) {
LOG_TRACE(Kernel_SVC, "called, event=0x{:08X}", handle);
const auto& handle_table = Core::CurrentProcess()->GetHandleTable();
- SharedPtr<Event> evt = handle_table.Get<Event>(handle);
+ SharedPtr<ReadableEvent> evt = handle_table.Get<ReadableEvent>(handle);
if (evt == nullptr) {
LOG_ERROR(Kernel_SVC, "Event handle does not exist, handle=0x{:08X}", handle);
return ERR_INVALID_HANDLE;
diff --git a/src/core/hle/kernel/writable_event.cpp b/src/core/hle/kernel/writable_event.cpp
new file mode 100644
index 000000000..a58ea6ec8
--- /dev/null
+++ b/src/core/hle/kernel/writable_event.cpp
@@ -0,0 +1,52 @@
+// 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/kernel.h"
+#include "core/hle/kernel/object.h"
+#include "core/hle/kernel/readable_event.h"
+#include "core/hle/kernel/thread.h"
+#include "core/hle/kernel/writable_event.h"
+
+namespace Kernel {
+
+WritableEvent::WritableEvent(KernelCore& kernel) : Object{kernel} {}
+WritableEvent::~WritableEvent() = default;
+
+EventPair WritableEvent::CreateEventPair(KernelCore& kernel, ResetType reset_type,
+ std::string name) {
+ SharedPtr<WritableEvent> writable_event(new WritableEvent(kernel));
+ SharedPtr<ReadableEvent> readable_event(new ReadableEvent(kernel));
+
+ writable_event->name = name + ":Writable";
+ writable_event->readable = readable_event;
+ readable_event->name = name + ":Readable";
+ readable_event->signaled = false;
+ readable_event->reset_type = reset_type;
+
+ return {std::move(readable_event), std::move(writable_event)};
+}
+
+SharedPtr<ReadableEvent> WritableEvent::GetReadableEvent() const {
+ return readable;
+}
+
+ResetType WritableEvent::GetResetType() const {
+ return readable->reset_type;
+}
+
+void WritableEvent::Signal() {
+ readable->Signal();
+}
+
+void WritableEvent::Clear() {
+ readable->Clear();
+}
+
+bool WritableEvent::IsSignaled() const {
+ return readable->signaled;
+}
+
+} // namespace Kernel
diff --git a/src/core/hle/kernel/event.h b/src/core/hle/kernel/writable_event.h
index 27d6126b0..fc57d18d7 100644
--- a/src/core/hle/kernel/event.h
+++ b/src/core/hle/kernel/writable_event.h
@@ -11,20 +11,29 @@
namespace Kernel {
class KernelCore;
+class ReadableEvent;
+class WritableEvent;
-class Event final : public WaitObject {
+struct EventPair {
+ SharedPtr<ReadableEvent> readable;
+ SharedPtr<WritableEvent> writable;
+};
+
+class WritableEvent final : public Object {
public:
+ ~WritableEvent() override;
+
/**
* Creates an event
* @param kernel The kernel instance to create this event under.
* @param reset_type ResetType describing how to create event
* @param name Optional name of event
*/
- static SharedPtr<Event> Create(KernelCore& kernel, ResetType reset_type,
- std::string name = "Unknown");
+ static EventPair CreateEventPair(KernelCore& kernel, ResetType reset_type,
+ std::string name = "Unknown");
std::string GetTypeName() const override {
- return "Event";
+ return "WritableEvent";
}
std::string GetName() const override {
return name;
@@ -35,25 +44,19 @@ public:
return HANDLE_TYPE;
}
- ResetType GetResetType() const {
- return reset_type;
- }
-
- bool ShouldWait(Thread* thread) const override;
- void Acquire(Thread* thread) override;
+ SharedPtr<ReadableEvent> GetReadableEvent() const;
- void WakeupAllWaitingThreads() override;
+ ResetType GetResetType() const;
void Signal();
void Clear();
+ bool IsSignaled() const;
private:
- explicit Event(KernelCore& kernel);
- ~Event() override;
+ explicit WritableEvent(KernelCore& kernel);
- ResetType reset_type; ///< Current ResetType
+ SharedPtr<ReadableEvent> readable;
- bool signaled; ///< Whether the event has already been signaled
std::string name; ///< Name of event (optional)
};