aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/hle/kernel/semaphore.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/semaphore.cpp
parent0c7498545f7f9beeb7e8070e1a1955a8d6f40bb6 (diff)
Kernel: Added WaitObject and changed "waitable" objects inherit from it.
Diffstat (limited to 'src/core/hle/kernel/semaphore.cpp')
-rw-r--r--src/core/hle/kernel/semaphore.cpp11
1 files changed, 3 insertions, 8 deletions
diff --git a/src/core/hle/kernel/semaphore.cpp b/src/core/hle/kernel/semaphore.cpp
index 88ec9a10..af2c465e 100644
--- a/src/core/hle/kernel/semaphore.cpp
+++ b/src/core/hle/kernel/semaphore.cpp
@@ -12,7 +12,7 @@
namespace Kernel {
-class Semaphore : public Object {
+class Semaphore : public WaitObject {
public:
std::string GetTypeName() const override { return "Semaphore"; }
std::string GetName() const override { return name; }
@@ -22,7 +22,6 @@ public:
s32 max_count; ///< Maximum number of simultaneous holders the semaphore can have
s32 available_count; ///< Number of free slots left in the semaphore
- std::queue<Handle> waiting_threads; ///< Threads that are waiting for the semaphore
std::string name; ///< Name of semaphore (optional)
/**
@@ -38,7 +37,7 @@ public:
if (wait) {
Kernel::WaitCurrentThread(WAITTYPE_SEMA, this);
- waiting_threads.push(GetCurrentThread()->GetHandle());
+ AddWaitingThread(GetCurrentThread());
} else {
--available_count;
}
@@ -83,11 +82,7 @@ ResultCode ReleaseSemaphore(s32* count, Handle handle, s32 release_count) {
// Notify some of the threads that the semaphore has been released
// stop once the semaphore is full again or there are no more waiting threads
- while (!semaphore->waiting_threads.empty() && semaphore->IsAvailable()) {
- Thread* thread = Kernel::g_handle_table.Get<Thread>(semaphore->waiting_threads.front()).get();
- if (thread != nullptr)
- thread->ResumeFromWait();
- semaphore->waiting_threads.pop();
+ while (semaphore->IsAvailable() && semaphore->ResumeNextThread() != nullptr) {
--semaphore->available_count;
}