Finished primary work on semaphores, implemented mutexing

This commit is contained in:
inspuration 2014-06-11 14:39:22 -04:00
parent 06c041fa79
commit 69769d4010
3 changed files with 29 additions and 8 deletions

View file

@ -34,7 +34,13 @@ public:
*/
Result SyncRequest(bool* wait) {
// TODO(bunnei): ImplementMe
locked = true;
if (!locked) {
locked = true;
*wait = false;
}
else {
*wait = true;
}
return 0;
}

View file

@ -34,6 +34,13 @@ public:
*/
Result SyncRequest(bool* wait) {
// TODO(bravia): ImplementMe
if (count > 0) {
count--;
*wait = false;
}
else{
*wait = true;
}
return 0;
}
@ -43,7 +50,10 @@ public:
* @return Result of operation, 0 on success, otherwise error code
*/
Result WaitSynchronization(bool* wait) {
// TODO(bravia): ImplementMe
*wait = (count == 0);
if (count == 0) {
Kernel::WaitCurrentThread(WAITTYPE_SEMA);
}
return 0;
}
};
@ -52,17 +62,22 @@ public:
/**
* Releases a semaphore
* @param unknown
* @param the previous count
* @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) {
Semaphore* sem = Kernel::g_object_pool.GetFast<Semaphore>(handle);
_assert_msg_(KERNEL, (sem != nullptr), "ReleaseSemaphore tried to release a nullptr sem!");
//TODO(bravia): ImplementMe
return 0;
*count = sem->count;
if (sem->count + release_count <= sem->max_count) {
sem->count += release_count;
return 0;
}
else {
return -1;
}
}
/**

View file

@ -284,7 +284,7 @@ Result CreateSemaphore(Handle* sem, s32 initial_count, s32 max_count) {
return 0;
}
/// Release a mutex
/// Release a Semaphore
Result ReleaseSemaphore(s32* count, Handle handle, s32 releaseCount) {
DEBUG_LOG(SVC, "called handle=0x%08X", handle);
_assert_msg_(KERNEL, (handle != 0), "called, but handle is nullptr!");