2021-10-30 14:18:21 +02:00
|
|
|
#pragma once
|
|
|
|
|
2021-10-30 15:30:19 +02:00
|
|
|
struct thread;
|
2021-10-30 14:18:21 +02:00
|
|
|
#include "cpu_context.h"
|
|
|
|
#include "mem.h"
|
2021-10-30 15:30:19 +02:00
|
|
|
#include "process.h"
|
2021-10-30 14:18:21 +02:00
|
|
|
|
|
|
|
#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;
|
2021-10-30 15:30:19 +02:00
|
|
|
|
2021-10-30 14:18:21 +02:00
|
|
|
unsigned long jiffiesSleeping;
|
|
|
|
int sleepHaveTimeouted;
|
2021-10-30 15:30:19 +02:00
|
|
|
|
|
|
|
struct thread *next, *prev;
|
|
|
|
struct thread *timeNext, *timePrev;
|
|
|
|
// For User thread only
|
|
|
|
struct thread *nextInProcess, *prevInProcess;
|
|
|
|
struct process *process;
|
2021-10-30 14:18:21 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
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);
|