diff options
| author | 2018-01-07 16:52:23 -0500 | |
|---|---|---|
| committer | 2018-01-07 16:52:23 -0500 | |
| commit | 4e33b4b42f404ff6250df15f1a48ed96ce839b77 (patch) | |
| tree | ea823ee6866e9c9a2e694d0e58c63ddb43ecf92f /src | |
| parent | wait_object: Refactor to allow waking up a single thread. (diff) | |
| download | yuzu-4e33b4b42f404ff6250df15f1a48ed96ce839b77.tar.gz yuzu-4e33b4b42f404ff6250df15f1a48ed96ce839b77.tar.xz yuzu-4e33b4b42f404ff6250df15f1a48ed96ce839b77.zip | |
semaphore: More changes for Switch.
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/kernel/semaphore.cpp | 20 | ||||
| -rw-r--r-- | src/core/hle/kernel/semaphore.h | 8 |
2 files changed, 17 insertions, 11 deletions
diff --git a/src/core/hle/kernel/semaphore.cpp b/src/core/hle/kernel/semaphore.cpp index 3f364661b..9c58aa42f 100644 --- a/src/core/hle/kernel/semaphore.cpp +++ b/src/core/hle/kernel/semaphore.cpp | |||
| @@ -14,7 +14,8 @@ namespace Kernel { | |||
| 14 | Semaphore::Semaphore() {} | 14 | Semaphore::Semaphore() {} |
| 15 | Semaphore::~Semaphore() {} | 15 | Semaphore::~Semaphore() {} |
| 16 | 16 | ||
| 17 | ResultVal<SharedPtr<Semaphore>> Semaphore::Create(VAddr guest_addr, VAddr mutex_addr, std::string name) { | 17 | ResultVal<SharedPtr<Semaphore>> Semaphore::Create(VAddr guest_addr, VAddr mutex_addr, |
| 18 | std::string name) { | ||
| 18 | SharedPtr<Semaphore> semaphore(new Semaphore); | 19 | SharedPtr<Semaphore> semaphore(new Semaphore); |
| 19 | 20 | ||
| 20 | // When the semaphore is created, some slots are reserved for other threads, | 21 | // When the semaphore is created, some slots are reserved for other threads, |
| @@ -37,23 +38,28 @@ bool Semaphore::ShouldWait(Thread* thread) const { | |||
| 37 | void Semaphore::Acquire(Thread* thread) { | 38 | void Semaphore::Acquire(Thread* thread) { |
| 38 | if (available_count <= 0) | 39 | if (available_count <= 0) |
| 39 | return; | 40 | return; |
| 41 | |||
| 40 | --available_count; | 42 | --available_count; |
| 41 | UpdateGuestState(); | 43 | UpdateGuestState(); |
| 42 | } | 44 | } |
| 43 | 45 | ||
| 44 | ResultVal<s32> Semaphore::Release(s32 release_count) { | 46 | ResultCode Semaphore::Release(s32 target) { |
| 45 | s32 previous_count = available_count; | 47 | ++available_count; |
| 46 | available_count += release_count; | ||
| 47 | UpdateGuestState(); | 48 | UpdateGuestState(); |
| 48 | 49 | ||
| 49 | WakeupAllWaitingThreads(); | 50 | if (target == -1) { |
| 51 | // When -1, wake up all waiting threads | ||
| 52 | WakeupAllWaitingThreads(); | ||
| 53 | } else { | ||
| 54 | // Otherwise, wake up just a single thread | ||
| 55 | WakeupWaitingThread(GetHighestPriorityReadyThread()); | ||
| 56 | } | ||
| 50 | 57 | ||
| 51 | return MakeResult<s32>(previous_count); | 58 | return RESULT_SUCCESS; |
| 52 | } | 59 | } |
| 53 | 60 | ||
| 54 | void Semaphore::UpdateGuestState() { | 61 | void Semaphore::UpdateGuestState() { |
| 55 | Memory::Write32(guest_addr, available_count); | 62 | Memory::Write32(guest_addr, available_count); |
| 56 | } | 63 | } |
| 57 | 64 | ||
| 58 | |||
| 59 | } // namespace Kernel | 65 | } // namespace Kernel |
diff --git a/src/core/hle/kernel/semaphore.h b/src/core/hle/kernel/semaphore.h index 9cad4450a..e80230cac 100644 --- a/src/core/hle/kernel/semaphore.h +++ b/src/core/hle/kernel/semaphore.h | |||
| @@ -50,11 +50,11 @@ public: | |||
| 50 | void Acquire(Thread* thread) override; | 50 | void Acquire(Thread* thread) override; |
| 51 | 51 | ||
| 52 | /** | 52 | /** |
| 53 | * Releases a certain number of slots from a semaphore. | 53 | * Releases a slot from a semaphore. |
| 54 | * @param release_count The number of slots to release | 54 | * @param target The number of threads to wakeup, -1 is all. |
| 55 | * @return The number of free slots the semaphore had before this call | 55 | * @return ResultCode indicating if the operation succeeded. |
| 56 | */ | 56 | */ |
| 57 | ResultVal<s32> Release(s32 release_count); | 57 | ResultCode Release(s32 target); |
| 58 | 58 | ||
| 59 | private: | 59 | private: |
| 60 | Semaphore(); | 60 | Semaphore(); |