feat: added task names

This commit is contained in:
2021-08-12 20:22:00 +02:00
parent be71f9a7e9
commit 94c6332e27
7 changed files with 32 additions and 12 deletions

View File

@@ -19,7 +19,7 @@ void task_start_first();
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);

View File

@@ -27,6 +27,10 @@ int strcmp(const char *s1, const char *s2);
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 *strncat(char *dest, const char *src, size_t n);

View File

@@ -132,7 +132,7 @@ void att_noreturn block_dev_task(void *data) {
void block_dev_start_task() {
block_semaphore = semaphore_create(1);
blockdev_task_running = true;
task_spawn(block_dev_task, NULL);
task_spawn(block_dev_task, NULL, "blockdev");
}
void block_dev_print_info() {

View File

@@ -83,7 +83,7 @@ void att_noreturn att_used kmain(multiboot_info_t *multiboot_info, uint32_t mb_n
kprint_start_task();
block_dev_start_task();
#ifdef K_SHELL
task_spawn(main_loop, NULL);
task_spawn(main_loop, NULL, "main");
#endif
// switch to tasking
syscall_start_scheduler();

View File

@@ -5,6 +5,7 @@
#include <string.h>
#include <sys/param.h>
#include <sys/types.h>
#include <myke/mem/malloc.h>
int memcpy(void *dst, const void *src, size_t amount) {
for (size_t i = 0; i < amount; i++) {
@@ -118,3 +119,14 @@ char *strncat(char *dest, const char *src, size_t n) {
}
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;
}

View File

@@ -64,5 +64,5 @@ void att_noreturn kprint_task(void *_) {
}
void kprint_start_task() {
task_spawn(kprint_task, NULL);
task_spawn(kprint_task, NULL, "kprint");
}

View File

@@ -27,19 +27,22 @@
int errno = 0;
typedef struct task {
// state
bool present: 1;
uint8_t state;
uint16_t wait_irq;
// identity
pid_t tid;
char* name;
int errno;
// linked list
struct task *next;
// persistence/memory
int errno;
void *stack;
uint32_t stack_page_count;
task_registers_t *task_registers;
} task_t;
@@ -240,10 +243,11 @@ void task_switch_next() {
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));
memset((uint8_t *) new_task, 0, sizeof(task_t));
new_task->tid = last_tid++;
new_task->name = strdup(name);
new_task->state = TASK_STATE_RUNNABLE;
new_task->stack = pmm_get_pages(16);
@@ -281,12 +285,12 @@ void task_free(task_t *task) {
}
void task_init() {
idle_task = task_create(task_idle, NULL);
reaper_pid = task_spawn(task_reaper, NULL);
idle_task = task_create(task_idle, NULL, "idle");
reaper_pid = task_spawn(task_reaper, NULL, "reaper");
}
pid_t task_spawn(task_entrypoint entrypoint, void *entry_data) {
task_t *new_task = task_create(entrypoint, entry_data);
pid_t task_spawn(task_entrypoint entrypoint, void *entry_data, char* name) {
task_t *new_task = task_create(entrypoint, entry_data, name);
if (first_task == NULL) {
// first task
first_task = new_task;