mirror of
https://github.com/citra-emu/citra.git
synced 2024-11-23 00:20:21 +00:00
Finished primary work on semaphores, implemented mutexing
This commit is contained in:
parent
06c041fa79
commit
69769d4010
@ -34,7 +34,13 @@ public:
|
|||||||
*/
|
*/
|
||||||
Result SyncRequest(bool* wait) {
|
Result SyncRequest(bool* wait) {
|
||||||
// TODO(bunnei): ImplementMe
|
// TODO(bunnei): ImplementMe
|
||||||
|
if (!locked) {
|
||||||
locked = true;
|
locked = true;
|
||||||
|
*wait = false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
*wait = true;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +34,13 @@ public:
|
|||||||
*/
|
*/
|
||||||
Result SyncRequest(bool* wait) {
|
Result SyncRequest(bool* wait) {
|
||||||
// TODO(bravia): ImplementMe
|
// TODO(bravia): ImplementMe
|
||||||
|
if (count > 0) {
|
||||||
|
count--;
|
||||||
|
*wait = false;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
*wait = true;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +50,10 @@ public:
|
|||||||
* @return Result of operation, 0 on success, otherwise error code
|
* @return Result of operation, 0 on success, otherwise error code
|
||||||
*/
|
*/
|
||||||
Result WaitSynchronization(bool* wait) {
|
Result WaitSynchronization(bool* wait) {
|
||||||
// TODO(bravia): ImplementMe
|
*wait = (count == 0);
|
||||||
|
if (count == 0) {
|
||||||
|
Kernel::WaitCurrentThread(WAITTYPE_SEMA);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -52,18 +62,23 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Releases a semaphore
|
* Releases a semaphore
|
||||||
* @param unknown
|
* @param the previous count
|
||||||
* @param handle Handle to mutex to release
|
* @param handle Handle to mutex to release
|
||||||
* @param unknown
|
* @param the number of increments to be made
|
||||||
*/
|
*/
|
||||||
Result ReleaseSemaphore(s32 * count, Handle handle, s32 release_count) {
|
Result ReleaseSemaphore(s32 * count, Handle handle, s32 release_count) {
|
||||||
Semaphore* sem = Kernel::g_object_pool.GetFast<Semaphore>(handle);
|
Semaphore* sem = Kernel::g_object_pool.GetFast<Semaphore>(handle);
|
||||||
|
|
||||||
_assert_msg_(KERNEL, (sem != nullptr), "ReleaseSemaphore tried to release a nullptr sem!");
|
_assert_msg_(KERNEL, (sem != nullptr), "ReleaseSemaphore tried to release a nullptr sem!");
|
||||||
|
|
||||||
//TODO(bravia): ImplementMe
|
*count = sem->count;
|
||||||
|
if (sem->count + release_count <= sem->max_count) {
|
||||||
|
sem->count += release_count;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a semaphore
|
* Creates a semaphore
|
||||||
|
@ -284,7 +284,7 @@ Result CreateSemaphore(Handle* sem, s32 initial_count, s32 max_count) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Release a mutex
|
/// Release a Semaphore
|
||||||
Result ReleaseSemaphore(s32* count, Handle handle, s32 releaseCount) {
|
Result ReleaseSemaphore(s32* count, Handle handle, s32 releaseCount) {
|
||||||
DEBUG_LOG(SVC, "called handle=0x%08X", handle);
|
DEBUG_LOG(SVC, "called handle=0x%08X", handle);
|
||||||
_assert_msg_(KERNEL, (handle != 0), "called, but handle is nullptr!");
|
_assert_msg_(KERNEL, (handle != 0), "called, but handle is nullptr!");
|
||||||
|
Loading…
Reference in New Issue
Block a user