diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2021-12-19 17:10:36 +0200 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2021-12-19 17:10:36 +0200 |
| commit | 9966b49db468de0168c7a455dfb5b4c66c413c4d (patch) | |
| tree | df31febe5e1ae52bae68ebe1df8b4469b97e0546 /common/tcb.c | |
| parent | 8bb1e280280c2f30740defca68ea643c56a3d880 (diff) | |
| download | kmi-9966b49db468de0168c7a455dfb5b4c66c413c4d.tar.gz kmi-9966b49db468de0168c7a455dfb5b4c66c413c4d.zip | |
Massive changes to jump to userspace
Diffstat (limited to 'common/tcb.c')
| -rw-r--r-- | common/tcb.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/common/tcb.c b/common/tcb.c new file mode 100644 index 0000000..5b00524 --- /dev/null +++ b/common/tcb.c @@ -0,0 +1,55 @@ +#include <apos/tcb.h> +#include <apos/utils.h> +#include <apos/sp_tree.h> + +static struct sp_root t_root = (struct sp_root){0}; + +#define tcb_container(x) \ + container_of(x, struct tcb, sp_n) + +void threads_insert(struct tcb *t) +{ + if(!sp_root(t_root)){ + sp_root(t_root) = &t->sp_n; + return; + } + + struct sp_node *n = sp_root(t_root), *p = NULL; + enum sp_dir d = LEFT; + + while(n){ + struct tcb *tc = tcb_container(n); + p = n; + + if(t->tid < tc->tid){ + n = sp_left(n); + d = LEFT; + } + + else { + n = sp_right(n); + d = RIGHT; + } + } + + sp_insert(&sp_root(t_root), p, &t->sp_n, d); +} + +struct tcb *threads_find(id_t tid) +{ + struct sp_node *n = sp_root(t_root); + + while(n){ + struct tcb *t = tcb_container(n); + + if(t->tid == tid) + return t; + + if(t->tid < tid) + n = sp_left(n); + else + n = sp_right(n); + } + + return 0; +} |
