2021-11-08 00:07:58 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "kthread.h"
|
|
|
|
#include "kthread_switch.h"
|
2021-11-11 01:50:02 +08:00
|
|
|
#include "condiction.h"
|
2021-11-08 00:07:58 +08:00
|
|
|
#include "../util/tree.h"
|
|
|
|
|
|
|
|
|
|
|
|
// holds internal data about a thread
|
|
|
|
typedef struct {
|
|
|
|
smp_thread_ID id; // thread id
|
|
|
|
|
|
|
|
// Niceness, less means higher priority. Cannot be negative
|
|
|
|
// A thread can wait nice ticks more than another thread waiting for the same time
|
|
|
|
unsigned int nice;
|
|
|
|
|
|
|
|
// Last tick at which the thread started waiting
|
2021-11-11 01:50:02 +08:00
|
|
|
uint64_t lastTick;
|
|
|
|
uint64_t sleepUntil;
|
|
|
|
smp_Condition *waitCondition;
|
2021-11-11 15:26:57 +08:00
|
|
|
void * waitData;
|
2021-11-08 00:07:58 +08:00
|
|
|
|
|
|
|
// Last-saved thread state after preemptive context switch
|
|
|
|
smp_thread_State state;
|
|
|
|
} __smp_Thread;
|
|
|
|
|
|
|
|
// variables defined in internal.c
|
|
|
|
|
|
|
|
// current tick number
|
|
|
|
extern uint64_t __smp_Now;
|
|
|
|
|
|
|
|
// number of cores in the system
|
|
|
|
extern int __smp_Count;
|
|
|
|
|
|
|
|
// should __smp_Switch not tick once
|
|
|
|
extern bool __smp_PauseTicker;
|
|
|
|
|
|
|
|
// __smp_Thread*[], current thread for each core
|
|
|
|
extern __smp_Thread **__smp_Current;
|
|
|
|
|
2021-11-08 01:34:06 +08:00
|
|
|
// largest thread ID
|
|
|
|
extern smp_thread_ID __smp_Idallo;
|
|
|
|
|
2021-11-08 00:07:58 +08:00
|
|
|
/* Priority = lastTick + nice
|
|
|
|
* So the average value is in fact constantly growing */
|
|
|
|
|
|
|
|
// [thread id] -> struct __smp_Thread
|
|
|
|
extern tree_Tree *__smp_Threads;
|
|
|
|
// [priority] -> struct __smp_Thread*
|
|
|
|
extern tree_Tree *__smp_ThreadsWaiting;
|