1

Implement SchedulerService

This commit is contained in:
2022-12-08 17:12:18 +01:00
parent 686efcb296
commit 14766941ca
2 changed files with 96 additions and 0 deletions

View File

@ -1 +1,37 @@
#include "SchedulerService.h"
namespace Kernel {
void SchedulerService::startScheduling() {
scheduler.start(scheduler.ready_queue.begin());
}
uint16_t SchedulerService::active() const {
return scheduler.get_active();
}
void SchedulerService::yield() {
scheduler.yield();
}
void SchedulerService::block() {
scheduler.block();
}
void SchedulerService::deblock(uint16_t tid) {
scheduler.deblock(tid);
}
void SchedulerService::exit() {
scheduler.exit();
}
void SchedulerService::suicide(uint16_t tid) {
scheduler.nice_kill(tid);
}
void SchedulerService::kill(uint16_t tid) {
scheduler.kill(tid);
}
}

View File

@ -1,4 +1,64 @@
#ifndef CHURLOS_SCHEDULERSERVICE_H
#define CHURLOS_SCHEDULERSERVICE_H
#include "Service.h"
#include "lib/memory/UniquePointer.h"
#include "kernel/process/Thread.h"
#include "kernel/process/Scheduler.h"
namespace Kernel {
/**
* This class implements the scheduling system service.
*/
class SchedulerService : public Service {
public:
static const constexpr uint8_t ID = Service::SCHEDULER;
public:
SchedulerService() = default;
// TODO: Rest of constructors
// Helper that directly constructs the thread, then readys it
template<typename T, typename... Args>
uint32_t ready(Args... args) {
Memory::unique_ptr<Thread> thread = Memory::make_unique<T>(std::forward<Args>(args)...);
uint32_t tid = thread->tid;
scheduler.ready(std::move(thread));
return tid;
}
/**
* Starts the first thread in the schedulers ready_queue.
*/
void startScheduling();
[[nodiscard]] uint16_t active() const;
/**
* Interrupts current thread execution and switch to the next thread.
*/
void yield();
void block();
void deblock(uint16_t tid);
void exit();
void suicide(uint16_t tid);
void kill(uint16_t tid);
// TODO: Thread that cleans up exited threads
private:
Scheduler scheduler;
};
}
#endif //CHURLOS_SCHEDULERSERVICE_H