diff options
| -rw-r--r-- | common/tcb.c | 15 | ||||
| -rw-r--r-- | include/apos/tcb.h | 4 | ||||
| -rw-r--r-- | include/apos/types.h | 7 |
3 files changed, 21 insertions, 5 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]; } diff --git a/include/apos/tcb.h b/include/apos/tcb.h index 9f10e2f..8f3be3d 100644 --- a/include/apos/tcb.h +++ b/include/apos/tcb.h @@ -133,7 +133,9 @@ struct tcb { */ id_t rid; - /** Thread ID. */ + /** Thread ID. @note all ids associated with threads use a signed type, + * but are always larger than zero. This is mirroring Linux behavior, + * and signed types are probably large enough. */ id_t tid; /** \todo implement cpu_id to hardware cpu ID translation, first in diff --git a/include/apos/types.h b/include/apos/types.h index e06ccd0..431d551 100644 --- a/include/apos/types.h +++ b/include/apos/types.h @@ -441,8 +441,11 @@ typedef int32_t ssize_t; /** Status, used with codes in \ref status_codes. */ typedef int_fast8_t stat_t; -/** ID of something. */ -typedef uint_fast32_t id_t; +/** ID of something. @todo should this be signed? Linux etc seems to assume it + * is with pids */ +typedef int_fast32_t id_t; + +#define ID_MAX INT_FAST32_MAX /** Memory region flags. */ typedef uint_fast16_t vmflags_t; |
