aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/hle/kernel/event.cpp
diff options
context:
space:
mode:
authorGravatar bunnei <bunneidev@gmail.com>2015-01-14 19:22:50 -0500
committerGravatar bunnei <bunneidev@gmail.com>2015-01-21 18:41:00 -0500
commitc22bac6398ff1705992fc44b2c29775c84cff662 (patch)
treee20da7e6e1824c19b7ced73f43815397749ffae7 /src/core/hle/kernel/event.cpp
parent0c7498545f7f9beeb7e8070e1a1955a8d6f40bb6 (diff)
Kernel: Added WaitObject and changed "waitable" objects inherit from it.
Diffstat (limited to 'src/core/hle/kernel/event.cpp')
-rw-r--r--src/core/hle/kernel/event.cpp26
1 files changed, 7 insertions, 19 deletions
diff --git a/src/core/hle/kernel/event.cpp b/src/core/hle/kernel/event.cpp
index 271190db..bf71e9ed 100644
--- a/src/core/hle/kernel/event.cpp
+++ b/src/core/hle/kernel/event.cpp
@@ -14,7 +14,7 @@
namespace Kernel {
-class Event : public Object {
+class Event : public WaitObject {
public:
std::string GetTypeName() const override { return "Event"; }
std::string GetName() const override { return name; }
@@ -27,16 +27,12 @@ public:
bool locked; ///< Event signal wait
bool permanent_locked; ///< Hack - to set event permanent state (for easy passthrough)
- std::vector<Handle> waiting_threads; ///< Threads that are waiting for the event
std::string name; ///< Name of event (optional)
ResultVal<bool> WaitSynchronization() override {
bool wait = locked;
if (locked) {
- Handle thread = GetCurrentThread()->GetHandle();
- if (std::find(waiting_threads.begin(), waiting_threads.end(), thread) == waiting_threads.end()) {
- waiting_threads.push_back(thread);
- }
+ AddWaitingThread(GetCurrentThread());
Kernel::WaitCurrentThread(WAITTYPE_EVENT, this);
}
if (reset_type != RESETTYPE_STICKY && !permanent_locked) {
@@ -86,20 +82,12 @@ ResultCode SignalEvent(const Handle handle) {
if (evt == nullptr) return InvalidHandle(ErrorModule::Kernel);
// Resume threads waiting for event to signal
- bool event_caught = false;
- for (size_t i = 0; i < evt->waiting_threads.size(); ++i) {
- Thread* thread = Kernel::g_handle_table.Get<Thread>(evt->waiting_threads[i]).get();
- if (thread != nullptr)
- thread->ResumeFromWait();
-
- // If any thread is signalled awake by this event, assume the event was "caught" and reset
- // the event. This will result in the next thread waiting on the event to block. Otherwise,
- // the event will not be reset, and the next thread to call WaitSynchronization on it will
- // not block. Not sure if this is correct behavior, but it seems to work.
- event_caught = true;
- }
- evt->waiting_threads.clear();
+ bool event_caught = evt->ResumeAllWaitingThreads();
+ // If any thread is signalled awake by this event, assume the event was "caught" and reset
+ // the event. This will result in the next thread waiting on the event to block. Otherwise,
+ // the event will not be reset, and the next thread to call WaitSynchronization on it will
+ // not block. Not sure if this is correct behavior, but it seems to work.
if (!evt->permanent_locked) {
evt->locked = event_caught;
}