summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSubv <subv2112@gmail.com>2014-12-13 04:22:11 +0100
committerSubv <subv2112@gmail.com>2014-12-13 19:40:18 +0100
commiteffb18188848477e98a97102f358d7d4a38bd566 (patch)
tree519fc4cca0d2f04733534d8a454acfb4364f51ad
parentKernel/Semaphores: Addressed some issues. (diff)
downloadyuzu-effb18188848477e98a97102f358d7d4a38bd566.tar
yuzu-effb18188848477e98a97102f358d7d4a38bd566.tar.gz
yuzu-effb18188848477e98a97102f358d7d4a38bd566.tar.bz2
yuzu-effb18188848477e98a97102f358d7d4a38bd566.tar.lz
yuzu-effb18188848477e98a97102f358d7d4a38bd566.tar.xz
yuzu-effb18188848477e98a97102f358d7d4a38bd566.tar.zst
yuzu-effb18188848477e98a97102f358d7d4a38bd566.zip
-rw-r--r--src/core/hle/kernel/semaphore.cpp20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/core/hle/kernel/semaphore.cpp b/src/core/hle/kernel/semaphore.cpp
index f7a895c3f..331d32069 100644
--- a/src/core/hle/kernel/semaphore.cpp
+++ b/src/core/hle/kernel/semaphore.cpp
@@ -20,9 +20,8 @@ public:
static Kernel::HandleType GetStaticHandleType() { return Kernel::HandleType::Semaphore; }
Kernel::HandleType GetHandleType() const override { return Kernel::HandleType::Semaphore; }
- u32 initial_count; ///< Number of entries reserved for other threads
u32 max_count; ///< Maximum number of simultaneous holders the semaphore can have
- u32 current_usage; ///< Number of currently used entries in the semaphore
+ u32 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)
@@ -31,17 +30,17 @@ public:
* @return Whether the semaphore is available
*/
bool IsAvailable() const {
- return current_usage < max_count;
+ return available_count > 0;
}
ResultVal<bool> WaitSynchronization() override {
- bool wait = current_usage == max_count;
+ bool wait = available_count == 0;
if (wait) {
Kernel::WaitCurrentThread(WAITTYPE_SEMA, GetHandle());
waiting_threads.push(GetCurrentThreadHandle());
} else {
- ++current_usage;
+ --available_count;
}
return MakeResult<bool>(wait);
@@ -60,11 +59,10 @@ ResultCode CreateSemaphore(Handle* handle, u32 initial_count,
Semaphore* semaphore = new Semaphore;
*handle = g_object_pool.Create(semaphore);
- semaphore->initial_count = initial_count;
// When the semaphore is created, some slots are reserved for other threads,
// and the rest is reserved for the caller thread
semaphore->max_count = max_count;
- semaphore->current_usage = max_count - initial_count;
+ semaphore->available_count = initial_count;
semaphore->name = name;
return RESULT_SUCCESS;
@@ -75,19 +73,19 @@ ResultCode ReleaseSemaphore(s32* count, Handle handle, s32 release_count) {
if (semaphore == nullptr)
return InvalidHandle(ErrorModule::Kernel);
- if (semaphore->current_usage < release_count)
+ if (semaphore->max_count - semaphore->available_count < release_count)
return ResultCode(ErrorDescription::OutOfRange, ErrorModule::Kernel,
ErrorSummary::InvalidArgument, ErrorLevel::Permanent);
- *count = semaphore->max_count - semaphore->current_usage;
- semaphore->current_usage = semaphore->current_usage - release_count;
+ *count = semaphore->available_count;
+ semaphore->available_count += 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()) {
Kernel::ResumeThreadFromWait(semaphore->waiting_threads.front());
semaphore->waiting_threads.pop();
- semaphore->current_usage++;
+ --semaphore->available_count;
}
return RESULT_SUCCESS;