From 7f8dfe2fd3e770c2e0435e9c56f5db5fd11ed6f7 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 31 Jan 2010 09:27:49 +0000 Subject: Implemented thread reference counters and related APIs. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1556 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/include/ch.h | 4 ++-- os/kernel/include/inline.h | 13 +++++++++++++ os/kernel/include/lists.h | 29 ++++++++++++++++++++++++----- os/kernel/include/threads.h | 11 +++++++++-- 4 files changed, 48 insertions(+), 9 deletions(-) (limited to 'os/kernel/include') diff --git a/os/kernel/include/ch.h b/os/kernel/include/ch.h index 4e35936ae..683c69cc6 100644 --- a/os/kernel/include/ch.h +++ b/os/kernel/include/ch.h @@ -35,7 +35,7 @@ /** * Kernel version string. */ -#define CH_KERNEL_VERSION "1.5.0unstable" +#define CH_KERNEL_VERSION "1.5.1unstable" /** * Kernel version major number. @@ -50,7 +50,7 @@ /** * Kernel version patch number. */ -#define CH_KERNEL_PATCH 0 +#define CH_KERNEL_PATCH 1 /* * Common values. diff --git a/os/kernel/include/inline.h b/os/kernel/include/inline.h index dbac5d553..6f6734893 100644 --- a/os/kernel/include/inline.h +++ b/os/kernel/include/inline.h @@ -67,6 +67,19 @@ static INLINE Thread *dequeue(Thread *tp) { tp->p_next->p_prev = tp->p_prev; return tp; } + +static INLINE void list_insert(Thread *tp, ThreadsList *tlp) { + + tp->p_next = tlp->p_next; + tlp->p_next = tp; +} + +static INLINE Thread *list_remove(ThreadsList *tlp) { + + Thread *tp = tlp->p_next; + tlp->p_next = tp->p_next; + return tp; +} #endif /* CH_OPTIMIZE_SPEED */ #endif /* _INLINE_H_ */ diff --git a/os/kernel/include/lists.h b/os/kernel/include/lists.h index 2ef0429ff..13d498939 100644 --- a/os/kernel/include/lists.h +++ b/os/kernel/include/lists.h @@ -30,17 +30,24 @@ typedef struct Thread Thread; /** - * Threads queue initialization. + * @brief Threads queue initialization. */ #define queue_init(tqp) ((tqp)->p_next = (tqp)->p_prev = (Thread *)(tqp)); /** - * Macro evaluating to @p TRUE if the specified threads queue is empty. + * @brief Threads list initialization. + */ +#define list_init(tlp) ((tlp)->p_next = (Thread *)(tlp)) + +/** + * @brief Evaluates to @p TRUE if the specified threads queue or list is + * empty. */ #define isempty(p) ((p)->p_next == (Thread *)(p)) /** - * Macro evaluating to @p TRUE if the specified threads queue is not empty. + * @brief Evaluates to @p TRUE if the specified threads queue or list is + * not empty. */ #define notempty(p) ((p)->p_next != (Thread *)(p)) @@ -66,11 +73,21 @@ typedef struct Thread Thread; */ typedef struct { Thread *p_next; /**< First @p Thread in the queue, or - @p ThreadQueue when empty.*/ + @p ThreadQueue when empty. */ Thread *p_prev; /**< Last @p Thread in the queue, or - @p ThreadQueue when empty.*/ + @p ThreadQueue when empty. */ } ThreadsQueue; +/** + * @brief Generic threads single link list, it works like a stack. + */ +typedef struct { + + Thread *p_next; /**< Last pushed @p Thread on the stack + list, or pointer to itself if + empty. */ +} ThreadsList; + #if !CH_OPTIMIZE_SPEED #ifdef __cplusplus @@ -81,6 +98,8 @@ extern "C" { Thread *fifo_remove(ThreadsQueue *tqp); Thread *lifo_remove(ThreadsQueue *tqp); Thread *dequeue(Thread *tp); + void list_insert(Thread *tp, ThreadsList *tlp); + Thread *list_remove(ThreadsList *tlp); #ifdef __cplusplus } #endif diff --git a/os/kernel/include/threads.h b/os/kernel/include/threads.h index f94beac32..a9209e6ea 100644 --- a/os/kernel/include/threads.h +++ b/os/kernel/include/threads.h @@ -54,6 +54,9 @@ struct Thread { /* End of the fields shared with the ThreadsQueue structure. */ tprio_t p_prio; /**< Thread priority. */ /* End of the fields shared with the ReadyList structure. */ +#if CH_USE_DYNAMIC + trefs_t p_refs; /**< References to this thread. */ +#endif tstate_t p_state; /**< Current thread state. */ tmode_t p_flags; /**< Various thread flags. */ struct context p_ctx; /**< Processor context. */ @@ -61,7 +64,7 @@ struct Thread { cnt_t p_locks; /**< Number of nested locks. */ #endif #if CH_DBG_THREADS_PROFILING - volatile systime_t p_time; /**< Thread consumed time in ticks. + volatile systime_t p_time; /**< Thread consumed time in ticks. @note This field can overflow. */ #endif union { @@ -76,7 +79,7 @@ struct Thread { #endif } p_u; /**< State-specific fields. */ #if CH_USE_WAITEXIT - Thread *p_waiting; /**< Thread waiting for termination.*/ + ThreadsList p_waiting; /**< Termination waiting list. */ #endif #if CH_USE_MESSAGES ThreadsQueue p_msgqueue; /**< Messages queue. */ @@ -167,6 +170,10 @@ extern "C" { void chThdSleepUntil(systime_t time); void chThdYield(void); void chThdExit(msg_t msg); +#if CH_USE_DYNAMIC + Thread *chThdAddRef(Thread *tp); + Thread *chThdRelease(Thread *tp); +#endif #if CH_USE_WAITEXIT msg_t chThdWait(Thread *tp); #endif -- cgit v1.2.3