mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-12-26 08:10:08 +00:00
semaphore: More changes for Switch.
This commit is contained in:
parent
0f6fbdb963
commit
4e33b4b42f
@ -14,7 +14,8 @@ namespace Kernel {
|
|||||||
Semaphore::Semaphore() {}
|
Semaphore::Semaphore() {}
|
||||||
Semaphore::~Semaphore() {}
|
Semaphore::~Semaphore() {}
|
||||||
|
|
||||||
ResultVal<SharedPtr<Semaphore>> Semaphore::Create(VAddr guest_addr, VAddr mutex_addr, std::string name) {
|
ResultVal<SharedPtr<Semaphore>> Semaphore::Create(VAddr guest_addr, VAddr mutex_addr,
|
||||||
|
std::string name) {
|
||||||
SharedPtr<Semaphore> semaphore(new Semaphore);
|
SharedPtr<Semaphore> semaphore(new Semaphore);
|
||||||
|
|
||||||
// When the semaphore is created, some slots are reserved for other threads,
|
// When the semaphore is created, some slots are reserved for other threads,
|
||||||
@ -37,23 +38,28 @@ bool Semaphore::ShouldWait(Thread* thread) const {
|
|||||||
void Semaphore::Acquire(Thread* thread) {
|
void Semaphore::Acquire(Thread* thread) {
|
||||||
if (available_count <= 0)
|
if (available_count <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
--available_count;
|
--available_count;
|
||||||
UpdateGuestState();
|
UpdateGuestState();
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<s32> Semaphore::Release(s32 release_count) {
|
ResultCode Semaphore::Release(s32 target) {
|
||||||
s32 previous_count = available_count;
|
++available_count;
|
||||||
available_count += release_count;
|
|
||||||
UpdateGuestState();
|
UpdateGuestState();
|
||||||
|
|
||||||
|
if (target == -1) {
|
||||||
|
// When -1, wake up all waiting threads
|
||||||
WakeupAllWaitingThreads();
|
WakeupAllWaitingThreads();
|
||||||
|
} else {
|
||||||
|
// Otherwise, wake up just a single thread
|
||||||
|
WakeupWaitingThread(GetHighestPriorityReadyThread());
|
||||||
|
}
|
||||||
|
|
||||||
return MakeResult<s32>(previous_count);
|
return RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Semaphore::UpdateGuestState() {
|
void Semaphore::UpdateGuestState() {
|
||||||
Memory::Write32(guest_addr, available_count);
|
Memory::Write32(guest_addr, available_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Kernel
|
} // namespace Kernel
|
||||||
|
@ -50,11 +50,11 @@ public:
|
|||||||
void Acquire(Thread* thread) override;
|
void Acquire(Thread* thread) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Releases a certain number of slots from a semaphore.
|
* Releases a slot from a semaphore.
|
||||||
* @param release_count The number of slots to release
|
* @param target The number of threads to wakeup, -1 is all.
|
||||||
* @return The number of free slots the semaphore had before this call
|
* @return ResultCode indicating if the operation succeeded.
|
||||||
*/
|
*/
|
||||||
ResultVal<s32> Release(s32 release_count);
|
ResultCode Release(s32 target);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Semaphore();
|
Semaphore();
|
||||||
|
Loading…
Reference in New Issue
Block a user