Support sleep
This commit is contained in:
@@ -48,6 +48,7 @@ Modification:
|
||||
#define SYSCALL_KILL 12 // kill the task by id
|
||||
|
||||
#define SYSCALL_SEMAPHORE 13 // semaphore related operations
|
||||
#define SYSCALL_SLEEP 14 // sleep
|
||||
// clang-format on
|
||||
|
||||
#ifndef __ASSEMBLER__
|
||||
@@ -113,4 +114,5 @@ int sys_unbind_irq_all(struct Thread* task);
|
||||
int sys_unbind_irq(struct Thread* task, int irq_num);
|
||||
|
||||
int sys_semaphore(sys_sem_option op, int sem_id);
|
||||
int sys_sleep(intptr_t ms);
|
||||
#endif
|
||||
|
||||
@@ -44,6 +44,7 @@ Modification:
|
||||
#define TASK_MAX_PRIORITY 32
|
||||
#define TASK_DEFAULT_PRIORITY 2
|
||||
#define TASK_NAME_MAX_LEN 16
|
||||
#define SLEEP_MONITOR_CORE 0
|
||||
|
||||
enum ProcState {
|
||||
INIT = 0,
|
||||
@@ -51,6 +52,7 @@ enum ProcState {
|
||||
RUNNING,
|
||||
DEAD,
|
||||
BLOCKED,
|
||||
SLEEPING,
|
||||
NEVER_RUN,
|
||||
};
|
||||
|
||||
@@ -72,6 +74,10 @@ struct ThreadContext {
|
||||
struct trapframe* trapframe;
|
||||
};
|
||||
|
||||
struct TaskSleepContext {
|
||||
int64_t remain_ms;
|
||||
};
|
||||
|
||||
/* Process Control Block */
|
||||
struct Thread {
|
||||
/* task name */
|
||||
@@ -97,6 +103,7 @@ struct Thread {
|
||||
|
||||
/* task schedule attributes */
|
||||
struct double_list_node node;
|
||||
struct TaskSleepContext sleep_context;
|
||||
enum ProcState state;
|
||||
int priority; // priority
|
||||
int remain_tick;
|
||||
@@ -114,6 +121,7 @@ struct XiziTaskManager {
|
||||
struct double_list_node task_list_head[TASK_MAX_PRIORITY]; /* list of task control blocks that are allocated */
|
||||
struct double_list_node task_running_list_head;
|
||||
struct double_list_node task_blocked_list_head;
|
||||
struct double_list_node task_sleep_list_head;
|
||||
struct XiziSemaphorePool semaphore_pool;
|
||||
|
||||
/* mem allocator */
|
||||
|
||||
Reference in New Issue
Block a user