mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-12 09:09:47 +12:00
[Kernel] Moar threads
This commit is contained in:
parent
920fd4cf0d
commit
134d63c515
4 changed files with 28 additions and 2 deletions
|
@ -83,6 +83,7 @@ private:
|
||||||
u32 getTLSPointer();
|
u32 getTLSPointer();
|
||||||
void setupIdleThread();
|
void setupIdleThread();
|
||||||
|
|
||||||
|
void acquireSyncObject(KernelObject* object, const Thread& thread);
|
||||||
bool isWaitable(const KernelObject* object);
|
bool isWaitable(const KernelObject* object);
|
||||||
|
|
||||||
// Functions for the err:f port
|
// Functions for the err:f port
|
||||||
|
|
|
@ -211,7 +211,7 @@ struct KernelObject {
|
||||||
return static_cast<T*>(data);
|
return static_cast<T*>(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* getTypeName() {
|
const char* getTypeName() const {
|
||||||
return kernelObjectTypeToString(type);
|
return kernelObjectTypeToString(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -101,6 +101,7 @@ void Kernel::waitSynchronization1() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!shouldWaitOnObject(object)) {
|
if (!shouldWaitOnObject(object)) {
|
||||||
|
acquireSyncObject(object, threads[currentThreadIndex]); // Acquire the object since it's ready
|
||||||
regs[0] = SVCResult::Success;
|
regs[0] = SVCResult::Success;
|
||||||
} else {
|
} else {
|
||||||
// Timeout is 0, don't bother waiting, instantly timeout
|
// Timeout is 0, don't bother waiting, instantly timeout
|
||||||
|
|
|
@ -186,6 +186,19 @@ void Kernel::sleepThreadOnArbiter(u32 waitingAddress) {
|
||||||
switchToNextThread();
|
switchToNextThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Kernel::acquireSyncObject(KernelObject* object, const Thread& thread) {
|
||||||
|
switch (object->type) {
|
||||||
|
case KernelObjectType::Mutex: {
|
||||||
|
Mutex* moo = object->getData<Mutex>();
|
||||||
|
moo->locked = true;
|
||||||
|
moo->ownerThread = thread.index;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default: Helpers::panic("Acquiring unimplemented sync object %s", object->getTypeName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Make a thread sleep for a certain amount of nanoseconds at minimum
|
// Make a thread sleep for a certain amount of nanoseconds at minimum
|
||||||
void Kernel::sleepThread(s64 ns) {
|
void Kernel::sleepThread(s64 ns) {
|
||||||
if (ns < 0) {
|
if (ns < 0) {
|
||||||
|
@ -353,8 +366,19 @@ bool Kernel::shouldWaitOnObject(KernelObject* object) {
|
||||||
case KernelObjectType::Event: // We should wait on an event only if it has not been signalled
|
case KernelObjectType::Event: // We should wait on an event only if it has not been signalled
|
||||||
return !object->getData<Event>()->fired;
|
return !object->getData<Event>()->fired;
|
||||||
|
|
||||||
|
case KernelObjectType::Mutex: {
|
||||||
|
Mutex* moo = object->getData<Mutex>(); // mooooooooooo
|
||||||
|
return moo->locked && moo->ownerThread != currentThreadIndex; // If the current thread owns the moo then no reason to wait
|
||||||
|
}
|
||||||
|
|
||||||
|
case KernelObjectType::Thread: // Waiting on a thread waits until it's dead. If it's dead then no need to wait
|
||||||
|
return object->getData<Thread>()->status != ThreadStatus::Dead;
|
||||||
|
|
||||||
|
case KernelObjectType::Semaphore:
|
||||||
|
Helpers::panic("No semaphore :(");
|
||||||
|
|
||||||
default:
|
default:
|
||||||
logThread("Not sure whether to wait on object (type: %s)", object->getTypeName());
|
Helpers::panic("Not sure whether to wait on object (type: %s)", object->getTypeName());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue