diff options
author | sotech117 <michael_foiani@brown.edu> | 2024-02-11 07:36:50 +0000 |
---|---|---|
committer | sotech117 <michael_foiani@brown.edu> | 2024-02-11 07:36:50 +0000 |
commit | 6cfe0ddd014597113e0635fcdecba9db0cc2c64b (patch) | |
tree | b40bbeda9f1e7ca44c1d59e75b94ed168310a959 /kernel/proc/kthread.c | |
parent | c71b9e406a8fb7bfcaeb20ee787d6eb4a1cbb71d (diff) |
basic implementation of most functions. not tested, but generally well thought out
Diffstat (limited to 'kernel/proc/kthread.c')
-rw-r--r-- | kernel/proc/kthread.c | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/kernel/proc/kthread.c b/kernel/proc/kthread.c index 1104b31..5f9917f 100644 --- a/kernel/proc/kthread.c +++ b/kernel/proc/kthread.c @@ -68,8 +68,36 @@ void kthread_init() kthread_t *kthread_create(proc_t *proc, kthread_func_t func, long arg1, void *arg2) { - NOT_YET_IMPLEMENTED("PROCS: kthread_create"); - return NULL; + // NOT_YET_IMPLEMENTED("PROCS: kthread_create"); + kthread_t *new_thread = slab_obj_alloc(kthread_allocator); + if (new_thread == NULL) + { + return NULL; + } + new_thread->kt_state = KT_NO_STATE; + + new_thread->kt_kstack = alloc_stack(); + if (new_thread->kt_kstack == NULL) + { + slab_obj_free(kthread_allocator, new_thread); + return NULL; + } + + new_thread->kt_proc = proc; + context_setup(&new_thread->kt_ctx, func, arg1, arg2, new_thread->kt_kstack, + DEFAULT_STACK_SIZE, new_thread->kt_proc->p_pml4); + + // give default values to rest of struct + new_thread->kt_retval = NULL; + new_thread->kt_errno = 0; + new_thread->kt_cancelled = 0; + new_thread->kt_wchan = NULL; + list_link_init(&new_thread->kt_plink); + list_link_init(&new_thread->kt_qlink); + list_init(&new_thread->kt_mutexes); + new_thread->kt_recent_core = 0; + + return new_thread; } /* @@ -124,7 +152,14 @@ void kthread_destroy(kthread_t *thr) */ void kthread_cancel(kthread_t *thr, void *retval) { - NOT_YET_IMPLEMENTED("PROCS: kthread_cancel"); + // NOT_YET_IMPLEMENTED("PROCS: kthread_cancel"); + KASSERT(thr != curthr); + + // TODO: ask about the use of check_curthr_cancelled() in syscall_handler() + thr->kt_retval = retval; + sched_cancel(thr); + + check_curthr_cancelled(); } /* @@ -132,5 +167,7 @@ void kthread_cancel(kthread_t *thr, void *retval) */ void kthread_exit(void *retval) { - NOT_YET_IMPLEMENTED("PROCS: kthread_exit"); + // NOT_YET_IMPLEMENTED("PROCS: kthread_exit"); + + proc_thread_exiting(retval); } |