More thread work

This commit is contained in:
wheremyfoodat 2022-12-07 02:08:18 +02:00
parent 7547159a48
commit ca4726aba1
6 changed files with 82 additions and 28 deletions

View file

@ -82,8 +82,8 @@ void Kernel::switchToNextThread() {
std::optional<int> newThreadIndex = getNextThread();
if (!newThreadIndex.has_value()) {
Helpers::warn("Kernel tried to switch to the next thread but none found. Switching to thread 0\n");
switchThread(0);
Helpers::warn("Kernel tried to switch to the next thread but none found. Switching to random thread\n");
switchThread(rand() % threadCount);
} else {
switchThread(newThreadIndex.value());
}
@ -301,4 +301,16 @@ bool Kernel::isWaitable(const KernelObject* object) {
using enum KernelObjectType;
return type == Event || type == Mutex || type == Port || type == Semaphore || type == Timer || type == Thread;
}
// Returns whether we should wait on a sync object or not
bool Kernel::shouldWaitOnObject(KernelObject* object) {
switch (object->type) {
case KernelObjectType::Event: // We should wait on an event only if it has not been signalled
return !object->getData<Event>()->fired;
default:
Helpers::warn("Not sure whether to wait on object (type: %s)", object->getTypeName());
return true;
}
}