[Kernel] Implement getThreadPriority

This commit is contained in:
wheremyfoodat 2022-10-16 01:01:09 +03:00
parent 08a45fc8a3
commit bb9a50ab31
3 changed files with 20 additions and 0 deletions

View file

@ -95,6 +95,7 @@ class Kernel {
void getResourceLimitCurrentValues();
void getSystemTick();
void getThreadID();
void getThreadPriority();
void releaseMutex();
void sendSyncRequest();
void signalEvent();

View file

@ -24,6 +24,7 @@ void Kernel::serviceSVC(u32 svc) {
case 0x02: queryMemory(); break;
case 0x08: createThread(); break;
case 0x0A: svcSleepThread(); break;
case 0x0B: getThreadPriority(); break;
case 0x13: createMutex(); break;
case 0x14: releaseMutex(); break;
case 0x17: createEvent(); break;

View file

@ -213,6 +213,24 @@ void Kernel::getThreadID() {
regs[1] = thread->getData<Thread>()->index;
}
void Kernel::getThreadPriority() {
const Handle handle = regs[1];
log("GetThreadPriority (handle = %X)\n", handle);
if (handle == KernelHandles::CurrentThread) {
regs[0] = SVCResult::Success;
regs[1] = threads[currentThreadIndex].priority;
} else {
auto object = getObject(handle, KernelObjectType::Thread);
if (object == nullptr) [[unlikely]] {
regs[0] = SVCResult::BadHandle;
} else {
regs[0] = SVCResult::Success;
regs[1] = object->getData<Thread>()->priority;
}
}
}
void Kernel::createMutex() {
bool locked = regs[1] != 0;
Helpers::panic("CreateMutex (initially locked: %s)\n", locked ? "yes" : "no");