#pragma once #include "cpu_context.h" #include "mem.h" #define THREAD_NAME_MAX_LENGTH 32 #define THREAD_DEFAULT_STACK_SIZE PAGE_SIZE typedef enum { RUNNING, READY, SLEEPING, WAITING, EXITING } thread_state; struct thread { char name[THREAD_NAME_MAX_LENGTH]; struct cpu_state *cpuState; thread_state state; vaddr_t stackAddr; size_t stackSize; unsigned long jiffiesSleeping; int sleepHaveTimeouted; struct thread *next; struct thread *prev; struct thread*timeNext; struct thread *timePrev; }; int threadSetup(vaddr_t mainStack, size_t mainStackSize); void threadExit(); struct thread *threadCreate(const char *name, cpu_kstate_function_arg1_t func, void *args); void threadDelete(struct thread *thread); struct thread *threadSelectNext(); struct cpu_state *threadSwitch(struct cpu_state *prevCpu); int threadYield(); int threadWait(struct thread *current, struct thread *next, unsigned long msec); int threadUnsched(struct thread *th); int threadMsleep(unsigned long msec); int threadOnJieffiesTick(); struct thread *getCurrentThread(); int threadAddThread(struct thread *th);