diff options
Diffstat (limited to 'tasking.cpp')
-rw-r--r-- | tasking.cpp | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/tasking.cpp b/tasking.cpp index 5cfe091..97dd51a 100644 --- a/tasking.cpp +++ b/tasking.cpp @@ -7,6 +7,7 @@ struct Task enum class State { Invalid, Staging, + Staged, Running }; @@ -33,14 +34,14 @@ void schedule(const Registers& regs) do { if (++current >= tasks.size()) current = 0; - } while (tasks[current].state == Task::Invalid); + } while (tasks[current].state == Task::Invalid || tasks[current].state == Task::Staging); asm volatile(R"( mov %0, %%esp mov %1, %%ebp )" :: "m" (tasks[current].esp), "m" (tasks[current].ebp)); - if (tasks[current].state == Task::Staging) { + if (tasks[current].state == Task::Staged) { tasks[current].state = Task::Running; asm volatile(R"( pop %eax @@ -69,7 +70,7 @@ bool tasking_spawn(void (*entry)(), unsigned ssize) if (i < 0) return false; - tasks[i] = Task(); + tasks[i].state = Task::Staging; auto stack = reinterpret_cast<std::uint32_t>(new std::uint8_t[ssize]); const auto stackend = stack + ssize; @@ -81,9 +82,11 @@ bool tasking_spawn(void (*entry)(), unsigned ssize) r->cs = 0x8; asm volatile("pushfl; pop %%eax" : "=a"(r->eflags)); - tasks[i].esp = regbase; - tasks[i].ebp = stackend; - tasks[i].state = Task::Staging; + tasks[i] = Task { + .esp = regbase, + .ebp = stackend, + .state = Task::Staged + }; return true; } |