os/kernel/tasking.h

58 lines
1.3 KiB
C
Raw Normal View History

2020-07-22 19:26:55 -05:00
#ifndef KERN_TASKING_H
#define KERN_TASKING_H
2019-02-11 09:30:28 -06:00
#include <stdint.h>
2020-07-22 19:35:23 -05:00
#include <sys/types.h>
2019-02-11 09:30:28 -06:00
2020-07-12 14:28:58 -05:00
#ifndef TASKING_H
2020-07-22 19:26:55 -05:00
2020-07-20 09:51:30 -05:00
typedef enum ThreadState {
THREAD_RUNNING,
THREAD_READY,
THREAD_EXITED,
THREAD_BLOCKED
} ThreadState;
2020-07-22 19:26:55 -05:00
2020-07-12 14:28:58 -05:00
#endif
2020-07-20 09:51:30 -05:00
struct Thread;
typedef struct Process {
char priv;
uint32_t pid;
uint32_t next_tid;
int numThreads;
int numThreadsBlocked;
struct Thread* firstThread;
} Process;
typedef struct Thread {
2019-05-21 19:16:19 -05:00
uint32_t kernel_esp;
uint32_t kernel_esp_top;
2020-07-20 09:51:30 -05:00
void* cr3; //In thread to make the task switch asm easier
uint32_t tid;
ThreadState state;
2019-05-11 10:11:28 -05:00
int errno;
2020-07-20 09:51:30 -05:00
struct Thread* nextThreadInProcess;
struct Thread* prevThreadInProcess;
struct Thread* nextReadyToRun;
struct Thread* prevReadyToRun;
Process* process;
} Thread;
2019-02-11 09:30:28 -06:00
2020-07-22 19:26:55 -05:00
extern Thread* currentThread;
void tasking_createTask(void* eip,void* cr3,char kmode,char param1_exists,uint32_t param1_arg,char param2_exists,uint32_t param2_arg,char isThread);
void tasking_init();
char tasking_isPrivleged();
pid_t tasking_getPID();
int* tasking_get_errno_address();
uint32_t tasking_new_thread(void* start,pid_t pid,char param_exists,uint32_t param_arg);
void tasking_exit(uint8_t code);
void tasking_block(ThreadState newstate);
void tasking_unblock(pid_t pid,uint32_t tid);
void tasking_yield();
2019-02-11 09:30:28 -06:00
#endif