diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2023-01-16 15:41:58 +0200 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2023-01-16 15:42:57 +0200 |
| commit | faf3710ec1024810d0255f6356cd0a9d12d2cf9b (patch) | |
| tree | 8a9fd697608b92cfd1f44966e534f1989e80cfda /common/tcb.c | |
| parent | d96dbf6384ef19fb3b43d315663936f43110eade (diff) | |
| download | kmi-faf3710ec1024810d0255f6356cd0a9d12d2cf9b.tar.gz kmi-faf3710ec1024810d0255f6356cd0a9d12d2cf9b.zip | |
make process ids signed
+ Unlikely to ever run into billions of threads, and this keeps in line
with stuff like Linux. Also allows C to relatively painlessly
implement hashmaps of pids, if neccessary.
Diffstat (limited to 'common/tcb.c')
| -rw-r--r-- | common/tcb.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/common/tcb.c b/common/tcb.c index fb2f934..19ae8a3 100644 --- a/common/tcb.c +++ b/common/tcb.c @@ -26,7 +26,7 @@ static id_t start_tid; /** Total number of possible thread IDs. */ -static size_t num_tids; +static id_t num_tids; /** Pointer to array of \ref tcb structures. Length of the array is \c num_tids.*/ static struct tcb **tcbs; @@ -62,8 +62,16 @@ void destroy_tcbs() */ static id_t __alloc_tid(struct tcb *t) { + id_t stop_tid = start_tid - 1; /** \todo this would need some locking or something... */ - for (size_t i = start_tid; i < num_tids; ++i) { + for (id_t i = start_tid; 1; ++i) { + if (i == ID_MAX) + i = 0; + + /* we're completely full */ + if (i == stop_tid) + return ERR_NF; + if (tcbs[i] || i == 0) continue; @@ -348,6 +356,9 @@ struct tcb *get_tcb(id_t tid) { hard_assert(tcbs, 0); + if (tid <= 0 || tid >= num_tids) + return NULL; + return tcbs[tid]; } |
