5b933a82d3
fix #1
48 lines
1.2 KiB
C
48 lines
1.2 KiB
C
#pragma once
|
|
|
|
#include "cpu_context.h"
|
|
#include "mem.h"
|
|
|
|
#define KTHREAD_NAME_MAX_LENGTH 32
|
|
#define KTHREAD_DEFAULT_STACK_SIZE PAGE_SIZE
|
|
|
|
|
|
typedef enum {
|
|
RUNNING,
|
|
READY,
|
|
SLEEPING,
|
|
WAITING,
|
|
EXITING
|
|
} kthread_state;
|
|
|
|
struct kthread {
|
|
char name[KTHREAD_NAME_MAX_LENGTH];
|
|
struct cpu_state *cpuState;
|
|
kthread_state state;
|
|
vaddr_t stackAddr;
|
|
size_t stackSize;
|
|
unsigned long jiffiesSleeping;
|
|
int sleepHaveTimeouted;
|
|
struct kthread *next;
|
|
struct kthread *prev;
|
|
struct kthread *timeNext;
|
|
struct kthread *timePrev;
|
|
};
|
|
|
|
int kthreadSetup(vaddr_t mainStack, size_t mainStackSize);
|
|
void kthreadExit();
|
|
|
|
struct kthread *kthreadCreate(const char *name, cpu_kstate_function_arg1_t func, void *args);
|
|
void kthreadDelete(struct kthread *thread);
|
|
|
|
struct kthread *kthreadSelectNext();
|
|
struct cpu_state *kthreadSwitch(struct cpu_state *prevCpu);
|
|
|
|
int kthreadYield();
|
|
int kthreadWait(struct kthread *current, struct kthread *next, unsigned long msec);
|
|
int kthreadUnsched(struct kthread *th);
|
|
int kthreadMsleep(unsigned long msec);
|
|
int kthreadOnJieffiesTick();
|
|
struct kthread *getCurrentThread();
|
|
int kthreadAddThread(struct kthread *th);
|