2020-04-23 00:49:09 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "cpu_context.h"
|
|
|
|
#include "mem.h"
|
|
|
|
|
|
|
|
#define KTHREAD_NAME_MAX_LENGTH 32
|
|
|
|
#define KTHREAD_DEFAULT_STACK_SIZE PAGE_SIZE
|
|
|
|
|
2020-05-03 14:45:26 +02:00
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
RUNNING,
|
|
|
|
READY,
|
|
|
|
SLEEPING,
|
2020-07-08 23:08:50 +02:00
|
|
|
WAITING,
|
2020-05-03 14:45:26 +02:00
|
|
|
EXITING
|
|
|
|
} kthread_state;
|
|
|
|
|
2020-04-23 00:49:09 +02:00
|
|
|
struct kthread {
|
2020-04-27 00:14:37 +02:00
|
|
|
char name[KTHREAD_NAME_MAX_LENGTH];
|
|
|
|
struct cpu_state *cpuState;
|
2020-05-03 14:45:26 +02:00
|
|
|
kthread_state state;
|
2020-04-27 00:14:37 +02:00
|
|
|
vaddr_t stackAddr;
|
|
|
|
size_t stackSize;
|
2020-05-03 14:45:26 +02:00
|
|
|
unsigned long jiffiesSleeping;
|
2020-04-27 00:14:37 +02:00
|
|
|
struct kthread *next;
|
|
|
|
struct kthread *prev;
|
2020-04-23 00:49:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
int kthreadSetup(vaddr_t mainStack, size_t mainStackSize);
|
2020-04-24 00:12:12 +02:00
|
|
|
void kthreadExit();
|
2020-04-23 00:49:09 +02:00
|
|
|
|
2020-04-24 23:34:34 +02:00
|
|
|
struct kthread *kthreadCreate(const char *name, cpu_kstate_function_arg1_t func, void *args);
|
2020-04-24 00:12:12 +02:00
|
|
|
void kthreadDelete(struct kthread *thread);
|
2020-04-23 00:49:09 +02:00
|
|
|
|
2020-04-24 00:12:12 +02:00
|
|
|
struct kthread *kthreadSelectNext();
|
2020-04-27 23:08:36 +02:00
|
|
|
struct cpu_state *kthreadSwitch(struct cpu_state *prevCpu);
|
2020-04-24 23:34:34 +02:00
|
|
|
|
|
|
|
int kthreadYield();
|
2020-07-08 23:08:50 +02:00
|
|
|
int kthreadSaveAndYield(struct kthread *);
|
2020-05-03 14:45:26 +02:00
|
|
|
int kthreadMsleep(unsigned long msec);
|
|
|
|
int kthreadOnJieffiesTick();
|
|
|
|
struct kthread *getCurrenThread();
|
2020-07-08 23:08:50 +02:00
|
|
|
int kthreadAddThread(struct kthread *th);
|
|
|
|
int kthreadUnsched(struct kthread *th);
|