feat: added task names
This commit is contained in:
@@ -19,7 +19,7 @@ void task_start_first();
|
|||||||
|
|
||||||
void task_switch_next();
|
void task_switch_next();
|
||||||
|
|
||||||
pid_t task_spawn(task_entrypoint, void *entry_data);
|
pid_t task_spawn(task_entrypoint, void *entry_data, char* name);
|
||||||
|
|
||||||
void task_end(pid_t tid);
|
void task_end(pid_t tid);
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,10 @@ int strcmp(const char *s1, const char *s2);
|
|||||||
|
|
||||||
int strncmp(const char *s1, const char *s2, int n);
|
int strncmp(const char *s1, const char *s2, int n);
|
||||||
|
|
||||||
|
char* strdup(const char* s);
|
||||||
|
|
||||||
|
char* strndup(const char* s, size_t n);
|
||||||
|
|
||||||
char *strcat(char *dest, const char *src);
|
char *strcat(char *dest, const char *src);
|
||||||
|
|
||||||
char *strncat(char *dest, const char *src, size_t n);
|
char *strncat(char *dest, const char *src, size_t n);
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ void att_noreturn block_dev_task(void *data) {
|
|||||||
void block_dev_start_task() {
|
void block_dev_start_task() {
|
||||||
block_semaphore = semaphore_create(1);
|
block_semaphore = semaphore_create(1);
|
||||||
blockdev_task_running = true;
|
blockdev_task_running = true;
|
||||||
task_spawn(block_dev_task, NULL);
|
task_spawn(block_dev_task, NULL, "blockdev");
|
||||||
}
|
}
|
||||||
|
|
||||||
void block_dev_print_info() {
|
void block_dev_print_info() {
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ void att_noreturn att_used kmain(multiboot_info_t *multiboot_info, uint32_t mb_n
|
|||||||
kprint_start_task();
|
kprint_start_task();
|
||||||
block_dev_start_task();
|
block_dev_start_task();
|
||||||
#ifdef K_SHELL
|
#ifdef K_SHELL
|
||||||
task_spawn(main_loop, NULL);
|
task_spawn(main_loop, NULL, "main");
|
||||||
#endif
|
#endif
|
||||||
// switch to tasking
|
// switch to tasking
|
||||||
syscall_start_scheduler();
|
syscall_start_scheduler();
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <myke/mem/malloc.h>
|
||||||
|
|
||||||
int memcpy(void *dst, const void *src, size_t amount) {
|
int memcpy(void *dst, const void *src, size_t amount) {
|
||||||
for (size_t i = 0; i < amount; i++) {
|
for (size_t i = 0; i < amount; i++) {
|
||||||
@@ -118,3 +119,14 @@ char *strncat(char *dest, const char *src, size_t n) {
|
|||||||
}
|
}
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char* strdup(const char* s) {
|
||||||
|
return strndup(s, strlen(s));
|
||||||
|
}
|
||||||
|
|
||||||
|
char* strndup(const char* s, size_t n) {
|
||||||
|
char* new = malloc(n + 1);
|
||||||
|
memcpy(new, s, n);
|
||||||
|
new[n] = 0;
|
||||||
|
return new;
|
||||||
|
}
|
||||||
|
|||||||
@@ -64,5 +64,5 @@ void att_noreturn kprint_task(void *_) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void kprint_start_task() {
|
void kprint_start_task() {
|
||||||
task_spawn(kprint_task, NULL);
|
task_spawn(kprint_task, NULL, "kprint");
|
||||||
}
|
}
|
||||||
@@ -27,19 +27,22 @@
|
|||||||
int errno = 0;
|
int errno = 0;
|
||||||
|
|
||||||
typedef struct task {
|
typedef struct task {
|
||||||
|
// state
|
||||||
bool present: 1;
|
bool present: 1;
|
||||||
uint8_t state;
|
uint8_t state;
|
||||||
uint16_t wait_irq;
|
uint16_t wait_irq;
|
||||||
|
|
||||||
|
// identity
|
||||||
pid_t tid;
|
pid_t tid;
|
||||||
|
char* name;
|
||||||
|
|
||||||
int errno;
|
// linked list
|
||||||
|
|
||||||
struct task *next;
|
struct task *next;
|
||||||
|
|
||||||
|
// persistence/memory
|
||||||
|
int errno;
|
||||||
void *stack;
|
void *stack;
|
||||||
uint32_t stack_page_count;
|
uint32_t stack_page_count;
|
||||||
|
|
||||||
task_registers_t *task_registers;
|
task_registers_t *task_registers;
|
||||||
} task_t;
|
} task_t;
|
||||||
|
|
||||||
@@ -240,10 +243,11 @@ void task_switch_next() {
|
|||||||
task_switch_next_inner(task_first_runnable());
|
task_switch_next_inner(task_first_runnable());
|
||||||
}
|
}
|
||||||
|
|
||||||
task_t *task_create(task_entrypoint entrypoint, void *entry_data) {
|
task_t *task_create(task_entrypoint entrypoint, void *entry_data, char* name) {
|
||||||
task_t *new_task = malloc(sizeof(task_t));
|
task_t *new_task = malloc(sizeof(task_t));
|
||||||
memset((uint8_t *) new_task, 0, sizeof(task_t));
|
memset((uint8_t *) new_task, 0, sizeof(task_t));
|
||||||
new_task->tid = last_tid++;
|
new_task->tid = last_tid++;
|
||||||
|
new_task->name = strdup(name);
|
||||||
new_task->state = TASK_STATE_RUNNABLE;
|
new_task->state = TASK_STATE_RUNNABLE;
|
||||||
|
|
||||||
new_task->stack = pmm_get_pages(16);
|
new_task->stack = pmm_get_pages(16);
|
||||||
@@ -281,12 +285,12 @@ void task_free(task_t *task) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void task_init() {
|
void task_init() {
|
||||||
idle_task = task_create(task_idle, NULL);
|
idle_task = task_create(task_idle, NULL, "idle");
|
||||||
reaper_pid = task_spawn(task_reaper, NULL);
|
reaper_pid = task_spawn(task_reaper, NULL, "reaper");
|
||||||
}
|
}
|
||||||
|
|
||||||
pid_t task_spawn(task_entrypoint entrypoint, void *entry_data) {
|
pid_t task_spawn(task_entrypoint entrypoint, void *entry_data, char* name) {
|
||||||
task_t *new_task = task_create(entrypoint, entry_data);
|
task_t *new_task = task_create(entrypoint, entry_data, name);
|
||||||
if (first_task == NULL) {
|
if (first_task == NULL) {
|
||||||
// first task
|
// first task
|
||||||
first_task = new_task;
|
first_task = new_task;
|
||||||
|
|||||||
Reference in New Issue
Block a user