Kernel: Convert Semaphore to not use Handles
This commit is contained in:
parent
4bb33dfc30
commit
d9b19be1d9
3 changed files with 87 additions and 66 deletions
|
@ -374,17 +374,38 @@ static Result GetThreadId(u32* thread_id, Handle handle) {
|
|||
|
||||
/// Creates a semaphore
|
||||
static Result CreateSemaphore(Handle* semaphore, s32 initial_count, s32 max_count) {
|
||||
ResultCode res = Kernel::CreateSemaphore(semaphore, initial_count, max_count);
|
||||
using Kernel::Semaphore;
|
||||
|
||||
ResultVal<SharedPtr<Semaphore>> semaphore_res = Semaphore::Create(initial_count, max_count);
|
||||
if (semaphore_res.Failed())
|
||||
return semaphore_res.Code().raw;
|
||||
|
||||
ResultVal<Handle> handle_res = Kernel::g_handle_table.Create(*semaphore_res);
|
||||
if (handle_res.Failed())
|
||||
return handle_res.Code().raw;
|
||||
|
||||
*semaphore = *handle_res;
|
||||
LOG_TRACE(Kernel_SVC, "called initial_count=%d, max_count=%d, created handle=0x%08X",
|
||||
initial_count, max_count, *semaphore);
|
||||
return res.raw;
|
||||
return RESULT_SUCCESS.raw;
|
||||
}
|
||||
|
||||
/// Releases a certain number of slots in a semaphore
|
||||
static Result ReleaseSemaphore(s32* count, Handle semaphore, s32 release_count) {
|
||||
LOG_TRACE(Kernel_SVC, "called release_count=%d, handle=0x%08X", release_count, semaphore);
|
||||
ResultCode res = Kernel::ReleaseSemaphore(count, semaphore, release_count);
|
||||
return res.raw;
|
||||
static Result ReleaseSemaphore(s32* count, Handle handle, s32 release_count) {
|
||||
using Kernel::Semaphore;
|
||||
|
||||
LOG_TRACE(Kernel_SVC, "called release_count=%d, handle=0x%08X", release_count, handle);
|
||||
|
||||
SharedPtr<Semaphore> semaphore = Kernel::g_handle_table.Get<Semaphore>(handle);
|
||||
if (semaphore == nullptr)
|
||||
return InvalidHandle(ErrorModule::Kernel).raw;
|
||||
|
||||
ResultVal<s32> release_res = semaphore->Release(release_count);
|
||||
if (release_res.Failed())
|
||||
return release_res.Code().raw;
|
||||
|
||||
*count = *release_res;
|
||||
return RESULT_SUCCESS.raw;
|
||||
}
|
||||
|
||||
/// Query memory
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue