Fixed multitasking bugs
This commit is contained in:
parent
9a3a11d78c
commit
2cc45e996f
4 changed files with 24 additions and 31 deletions
|
@ -11,8 +11,6 @@ namespace MTGosHAL {
|
|||
uint32_t tss[32];
|
||||
protected:
|
||||
private:
|
||||
static auto task_a() -> void;
|
||||
static auto task_b() -> void;
|
||||
Task* first_task;
|
||||
Task* curr_task;
|
||||
};
|
||||
|
@ -26,6 +24,7 @@ namespace MTGosHAL {
|
|||
auto unpause() -> struct cpu_state*;
|
||||
auto pause(struct cpu_state*) -> Task *;
|
||||
auto addTask(Task*) -> void;
|
||||
auto hasNext() -> bool;
|
||||
};
|
||||
|
||||
} // namespace MTGosHAL
|
||||
|
|
|
@ -14,8 +14,6 @@ namespace MTGosHAL {
|
|||
uint32_t tss[32];
|
||||
protected:
|
||||
private:
|
||||
static auto task_a() -> void;
|
||||
static auto task_b() -> void;
|
||||
Task* first_task;
|
||||
Task* curr_task;
|
||||
};
|
||||
|
@ -29,6 +27,7 @@ namespace MTGosHAL {
|
|||
auto unpause() -> struct cpu_state*;
|
||||
auto pause(struct cpu_state*) -> Task *;
|
||||
auto addTask(Task*) -> void;
|
||||
auto hasNext() -> bool;
|
||||
};
|
||||
|
||||
} // namespace MTGosHAL
|
||||
|
|
|
@ -55,40 +55,24 @@ auto Multitasking::initTask(void(* entry)()) -> struct cpu_state*
|
|||
else {
|
||||
first_task=task;
|
||||
}
|
||||
curr_task=first_task;
|
||||
return state;
|
||||
}
|
||||
|
||||
auto Multitasking::task_a() -> void
|
||||
{
|
||||
while(true) {
|
||||
char arr[513];
|
||||
arr[512]=0;
|
||||
disk.readSector(disk.getDriveNumByName("ATA0m"),0,(uint8_t*)arr);
|
||||
out << arr;
|
||||
}
|
||||
}
|
||||
|
||||
auto Multitasking::task_b() -> void
|
||||
{
|
||||
while(true) {
|
||||
char arr[513];
|
||||
arr[512]=0;
|
||||
disk.readSector(disk.getDriveNumByName("ATA0m"),1,(uint8_t*)arr);
|
||||
out << arr;
|
||||
}
|
||||
}
|
||||
auto Multitasking::schedule(struct cpu_state* cpu) -> struct cpu_state*
|
||||
{
|
||||
Task* next=curr_task->pause(cpu);
|
||||
if(next==nullptr)
|
||||
Task* next=nullptr;
|
||||
if(curr_task) {
|
||||
next=curr_task->pause(cpu);
|
||||
}
|
||||
if (!next) {
|
||||
next=first_task;
|
||||
}
|
||||
curr_task=next;
|
||||
return next->unpause();
|
||||
}
|
||||
Task::Task(struct cpu_state* cpu): cpu_state(cpu), next(nullptr) {};
|
||||
//This is run every time this task is chosen by the scheduler
|
||||
auto Task::unpause() -> struct cpu_state* {
|
||||
MTGosHAL::tasks.tss[1] = (uint32_t) (cpu_state + 1);
|
||||
return cpu_state;
|
||||
}
|
||||
//This is run every time the timer ticks and a task is running
|
||||
|
@ -101,4 +85,7 @@ auto Task::addTask(Task* task) -> void {
|
|||
return next->addTask(task);
|
||||
next=task;
|
||||
}
|
||||
auto Task::hasNext() -> bool {
|
||||
return next!=nullptr;
|
||||
}
|
||||
} // namespace MTGosHAL
|
||||
|
|
|
@ -6,20 +6,28 @@
|
|||
#include <Multitasking.h>
|
||||
#include <blockdev.hpp>
|
||||
using namespace MTGosHAL;
|
||||
void pid_null() {
|
||||
for(;;);
|
||||
}
|
||||
void task_a() {
|
||||
while(true)
|
||||
MTGosHAL::out << "a";
|
||||
}
|
||||
void task_b() {
|
||||
while(true)
|
||||
MTGosHAL::out << "b";
|
||||
}
|
||||
void task_c() {
|
||||
while(true)
|
||||
MTGosHAL::out << "c";
|
||||
}
|
||||
void task_d() {
|
||||
while(true)
|
||||
MTGosHAL::out << "d";
|
||||
}
|
||||
void main() {
|
||||
MTGosHAL::out << "Initializing Kernel!\n";
|
||||
MTGosHAL::tasks.initTask(&pid_null);
|
||||
MTGosHAL::tasks.initTask(&task_a);
|
||||
MTGosHAL::tasks.initTask(&task_b);
|
||||
MTGosHAL::tasks.initTask(&task_c);
|
||||
|
|
Loading…
Reference in a new issue