Newer
Older
tree-os / src / kernel / lib / task / task.h
@lukas lukas on 30 May 2021 1005 bytes basic task communication
#ifndef TASK_H
#define TASK_H

#include <stdint.h>
#include <lib/task/message.h>

extern void initTasking();
 
typedef struct __attribute__ ((packed)) {
    uint32_t eax, ebx, ecx, edx, esi, edi, esp, ebp, eip, eflags, cr3;
} Registers;
 
typedef struct Task {
    Registers registers; // the register states for the task
    struct Task *nextTask; // linked list of tasks that need to be done
    void* stack;
    Message* message;
} Task;
 
extern void initTasking();
extern void createTask(Task *task, uint32_t mainFunction, uint32_t flags, uint32_t *pagedir);
 
extern void yield();
extern void yields(); // yield, but schedule the currently running task
extern void switchTask(Registers *old, Registers *new);
extern void schedule(Task* task); // schedule a task to be run in the future
extern void destroyCurrentTask();

extern void setRunningTask(Task* task); // set the task currently executed
extern void sendMessage(Task* task, Message* message);

extern Message* popMessage(Task* task);

#endif