summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/event.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2015-01-14 19:22:50 -0500
committerGravatar bunnei2015-01-21 18:41:00 -0500
commitc22bac6398ff1705992fc44b2c29775c84cff662 (patch)
treee20da7e6e1824c19b7ced73f43815397749ffae7 /src/core/hle/kernel/event.cpp
parentMerge pull request #491 from archshift/hidspvr (diff)
downloadyuzu-c22bac6398ff1705992fc44b2c29775c84cff662.tar.gz
yuzu-c22bac6398ff1705992fc44b2c29775c84cff662.tar.xz
yuzu-c22bac6398ff1705992fc44b2c29775c84cff662.zip
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 271190dbe..bf71e9edb 100644
--- a/src/core/hle/kernel/event.cpp
+++ b/src/core/hle/kernel/event.cpp
@@ -14,7 +14,7 @@
14 14
15namespace Kernel { 15namespace Kernel {
16 16
17class Event : public Object { 17class Event : public WaitObject {
18public: 18public:
19 std::string GetTypeName() const override { return "Event"; } 19 std::string GetTypeName() const override { return "Event"; }
20 std::string GetName() const override { return name; } 20 std::string GetName() const override { return name; }
@@ -27,16 +27,12 @@ public:
27 27
28 bool locked; ///< Event signal wait 28 bool locked; ///< Event signal wait
29 bool permanent_locked; ///< Hack - to set event permanent state (for easy passthrough) 29 bool permanent_locked; ///< Hack - to set event permanent state (for easy passthrough)
30 std::vector<Handle> waiting_threads; ///< Threads that are waiting for the event
31 std::string name; ///< Name of event (optional) 30 std::string name; ///< Name of event (optional)
32 31
33 ResultVal<bool> WaitSynchronization() override { 32 ResultVal<bool> WaitSynchronization() override {
34 bool wait = locked; 33 bool wait = locked;
35 if (locked) { 34 if (locked) {
36 Handle thread = GetCurrentThread()->GetHandle(); 35 AddWaitingThread(GetCurrentThread());
37 if (std::find(waiting_threads.begin(), waiting_threads.end(), thread) == waiting_threads.end()) {
38 waiting_threads.push_back(thread);
39 }
40 Kernel::WaitCurrentThread(WAITTYPE_EVENT, this); 36 Kernel::WaitCurrentThread(WAITTYPE_EVENT, this);
41 } 37 }
42 if (reset_type != RESETTYPE_STICKY && !permanent_locked) { 38 if (reset_type != RESETTYPE_STICKY && !permanent_locked) {
@@ -86,20 +82,12 @@ ResultCode SignalEvent(const Handle handle) {
86 if (evt == nullptr) return InvalidHandle(ErrorModule::Kernel); 82 if (evt == nullptr) return InvalidHandle(ErrorModule::Kernel);
87 83
88 // Resume threads waiting for event to signal 84 // Resume threads waiting for event to signal
89 bool event_caught = false; 85 bool event_caught = evt->ResumeAllWaitingThreads();
90 for (size_t i = 0; i < evt->waiting_threads.size(); ++i) {
91 Thread* thread = Kernel::g_handle_table.Get<Thread>(evt->waiting_threads[i]).get();
92 if (thread != nullptr)
93 thread->ResumeFromWait();
94
95 // If any thread is signalled awake by this event, assume the event was "caught" and reset
96 // the event. This will result in the next thread waiting on the event to block. Otherwise,
97 // the event will not be reset, and the next thread to call WaitSynchronization on it will
98 // not block. Not sure if this is correct behavior, but it seems to work.
99 event_caught = true;
100 }
101 evt->waiting_threads.clear();
102 86
87 // If any thread is signalled awake by this event, assume the event was "caught" and reset
88 // the event. This will result in the next thread waiting on the event to block. Otherwise,
89 // the event will not be reset, and the next thread to call WaitSynchronization on it will
90 // not block. Not sure if this is correct behavior, but it seems to work.
103 if (!evt->permanent_locked) { 91 if (!evt->permanent_locked) {
104 evt->locked = event_caught; 92 evt->locked = event_caught;
105 } 93 }