summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar bunnei2018-01-07 16:52:23 -0500
committerGravatar bunnei2018-01-07 16:52:23 -0500
commit4e33b4b42f404ff6250df15f1a48ed96ce839b77 (patch)
treeea823ee6866e9c9a2e694d0e58c63ddb43ecf92f /src
parentwait_object: Refactor to allow waking up a single thread. (diff)
downloadyuzu-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.cpp20
-rw-r--r--src/core/hle/kernel/semaphore.h8
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 {
14Semaphore::Semaphore() {} 14Semaphore::Semaphore() {}
15Semaphore::~Semaphore() {} 15Semaphore::~Semaphore() {}
16 16
17ResultVal<SharedPtr<Semaphore>> Semaphore::Create(VAddr guest_addr, VAddr mutex_addr, std::string name) { 17ResultVal<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 {
37void Semaphore::Acquire(Thread* thread) { 38void 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
44ResultVal<s32> Semaphore::Release(s32 release_count) { 46ResultCode 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
54void Semaphore::UpdateGuestState() { 61void 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
59private: 59private:
60 Semaphore(); 60 Semaphore();