aboutsummaryrefslogtreecommitdiff
path: root/common/tcb.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/tcb.c')
-rw-r--r--common/tcb.c15
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];
}