From ec989bbe7d9bb7a844eeddeceaeb7bb7e4d5dab6 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Fri, 21 Oct 2022 17:43:31 +0300 Subject: initial implementation of swap + Slightly unsure if it should be a syscall, or if assign would be enough. Also, which thread should run in a fork/spawn? For now, old thread, though this might increase latency. Or add swap flag to these calls? --- common/uapi/proc.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'common/uapi/proc.c') diff --git a/common/uapi/proc.c b/common/uapi/proc.c index a668246..a9a3dce 100644 --- a/common/uapi/proc.c +++ b/common/uapi/proc.c @@ -12,6 +12,8 @@ #include #include +#include + /** * Create syscall handler. * @@ -122,10 +124,15 @@ SYSCALL_DEFINE1(kill)(sys_arg_t tid) * @return \ref OK and 0. */ SYSCALL_DEFINE1(swap)(sys_arg_t tid){ - /** \todo switch to process */ - /** \todo should switch return the registers of the new thread that would - * be used for message passing? */ - return (struct sys_ret){ OK, 0, 0, 0, 0, 0 }; + struct tcb *t = get_tcb(tid); + if (!t) + /** @todo add error sys_ret macro? */ + return (struct sys_ret){ERR_INVAL, 0, 0, 0, 0, 0}; + + /* switch over to new thread */ + use_tcb(t); + + return get_args(t); } /** -- cgit v1.3