diff options
Diffstat (limited to 'common')
| -rw-r--r-- | common/tcb.c | 17 | ||||
| -rw-r--r-- | common/uapi/ipc.c | 2 |
2 files changed, 10 insertions, 9 deletions
diff --git a/common/tcb.c b/common/tcb.c index 4b57c06..c0f82cc 100644 --- a/common/tcb.c +++ b/common/tcb.c @@ -23,7 +23,7 @@ /* arguably exessively many globals... */ /** Thread ID to start looking from when allocating new ID. */ -static id_t start_tid; +static id_t start_tid = 0; /** Total number of possible thread IDs. */ static id_t num_tids; @@ -46,6 +46,7 @@ void init_tcbs() * something smaller but this is fine for now. */ tcbs = (struct tcb **)alloc_page(MM_O1); num_tids = order_size(MM_O1) / sizeof(struct tcb *); + catastrophic_assert(is_powerof2(num_tids)); memset(tcbs, 0, order_size(MM_O1)); } @@ -64,18 +65,18 @@ static id_t __alloc_tid(struct tcb *t) { id_t stop_tid = start_tid - 1; /** \todo this would need some locking or something... */ - for (id_t i = start_tid; 1; ++i) { - if (i == ID_MAX) - i = 0; + for (id_t i = start_tid;; ++i) { + if (i <= 0) + i = 1; /* we're completely full */ if (i == stop_tid) return ERR_NF; - if (tcbs[i] || i == 0) + if (get_tcb(i) || i == 0) continue; - tcbs[i] = t; + tcbs[i & (num_tids - 1)] = t; start_tid = i + 1; return i; } @@ -292,10 +293,10 @@ struct tcb *get_tcb(id_t tid) { hard_assert(tcbs, 0); - if (tid <= 0 || tid >= num_tids) + if (tid <= 0) return NULL; - return tcbs[tid]; + return tcbs[tid & (num_tids - 1)]; } void set_return(struct tcb *t, vm_t v) diff --git a/common/uapi/ipc.c b/common/uapi/ipc.c index 18c3b1a..cb2ce28 100644 --- a/common/uapi/ipc.c +++ b/common/uapi/ipc.c @@ -216,7 +216,7 @@ static void do_ipc(struct tcb *t, if (unlikely(!enough_rpc_stack(t))) return_args1(t, ERR_OOMEM); - vm_t s = enter_rpc(t, SYS_RET6(OK, t->eid, d0, d1, d2, d3), kind); + vm_t s = enter_rpc(t, SYS_RET6(t->eid, t->tid, d0, d1, d2, d3), kind); struct tcb *r = get_tcb(pid); if (unlikely(!r)) { |
