sched: add struct and object types for task and thread objects
This commit is contained in:
2
Makefile
2
Makefile
@@ -19,7 +19,7 @@ include arch/$(SOCKS_ARCH)/config.mk
|
|||||||
# Platform-independent kernel source files
|
# Platform-independent kernel source files
|
||||||
####################################
|
####################################
|
||||||
|
|
||||||
KERNEL_SRC_DIRS := init kernel vm ds util obj test
|
KERNEL_SRC_DIRS := init kernel vm ds util obj sched test
|
||||||
KERNEL_C_FILES := $(foreach dir,$(KERNEL_SRC_DIRS),$(wildcard $(dir)/*.c))
|
KERNEL_C_FILES := $(foreach dir,$(KERNEL_SRC_DIRS),$(wildcard $(dir)/*.c))
|
||||||
KERNEL_OBJ := $(addprefix $(BUILD_DIR)/,$(KERNEL_C_FILES:.c=.o))
|
KERNEL_OBJ := $(addprefix $(BUILD_DIR)/,$(KERNEL_C_FILES:.c=.o))
|
||||||
|
|
||||||
|
|||||||
43
include/socks/sched.h
Normal file
43
include/socks/sched.h
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
#ifndef SOCKS_SCHED_H_
|
||||||
|
#define SOCKS_SCHED_H_
|
||||||
|
|
||||||
|
#include <socks/pmap.h>
|
||||||
|
#include <socks/queue.h>
|
||||||
|
#include <socks/btree.h>
|
||||||
|
#include <socks/status.h>
|
||||||
|
|
||||||
|
typedef enum task_state {
|
||||||
|
TASK_RUNNING,
|
||||||
|
TASK_STOPPED,
|
||||||
|
} task_state_t;
|
||||||
|
|
||||||
|
typedef enum task_thread_state {
|
||||||
|
TASK_THREAD_READY,
|
||||||
|
TASK_THREAD_SLEEPING,
|
||||||
|
TASK_THREAD_STOPPED,
|
||||||
|
} task_thread_state_t;
|
||||||
|
|
||||||
|
typedef struct task {
|
||||||
|
struct task *t_parent;
|
||||||
|
unsigned int t_id;
|
||||||
|
task_state_t t_state;
|
||||||
|
|
||||||
|
pmap_t t_pmap;
|
||||||
|
|
||||||
|
btree_node_t t_tasklist;
|
||||||
|
queue_t t_threads;
|
||||||
|
queue_t t_children;
|
||||||
|
} task_t;
|
||||||
|
|
||||||
|
typedef struct task_thread {
|
||||||
|
task_thread_state_t tr_state;
|
||||||
|
unsigned int tr_id;
|
||||||
|
unsigned int tr_prio;
|
||||||
|
|
||||||
|
queue_entry_t tr_threads;
|
||||||
|
void *tr_kstack;
|
||||||
|
} task_thread_t;
|
||||||
|
|
||||||
|
extern kern_status_t sched_init(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <socks/test.h>
|
#include <socks/test.h>
|
||||||
#include <socks/printk.h>
|
#include <socks/printk.h>
|
||||||
#include <socks/object.h>
|
#include <socks/object.h>
|
||||||
|
#include <socks/sched.h>
|
||||||
#include <socks/machine/init.h>
|
#include <socks/machine/init.h>
|
||||||
#include <socks/machine/cpu.h>
|
#include <socks/machine/cpu.h>
|
||||||
|
|
||||||
@@ -20,6 +21,7 @@ void kernel_init(uintptr_t arg)
|
|||||||
ml_init(arg);
|
ml_init(arg);
|
||||||
|
|
||||||
object_bootstrap();
|
object_bootstrap();
|
||||||
|
sched_init();
|
||||||
|
|
||||||
run_all_tests();
|
run_all_tests();
|
||||||
|
|
||||||
|
|||||||
31
sched/sched.c
Normal file
31
sched/sched.c
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#include <socks/object.h>
|
||||||
|
#include <socks/sched.h>
|
||||||
|
#include <socks/printk.h>
|
||||||
|
|
||||||
|
static object_type_t task_type = {
|
||||||
|
.ob_name = "task",
|
||||||
|
.ob_size = sizeof(task_t),
|
||||||
|
};
|
||||||
|
|
||||||
|
static object_type_t thread_type = {
|
||||||
|
.ob_name = "thread",
|
||||||
|
.ob_size = sizeof(task_thread_t),
|
||||||
|
};
|
||||||
|
|
||||||
|
kern_status_t sched_init(void)
|
||||||
|
{
|
||||||
|
kern_status_t status = KERN_OK;
|
||||||
|
|
||||||
|
status = object_type_register(&task_type);
|
||||||
|
if (status != KERN_OK) {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
status = object_type_register(&thread_type);
|
||||||
|
if (status != KERN_OK) {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
printk("sched: initialised");
|
||||||
|
return status;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user