From fbb8e866760c1bc605422c92eef756903e5d63df Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Tue, 5 Apr 2016 10:07:57 +0000 Subject: Scheduler queues modified in a more readable and safer way. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9241 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/rt/include/chschd.h | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) (limited to 'os/rt/include/chschd.h') diff --git a/os/rt/include/chschd.h b/os/rt/include/chschd.h index a00b2fa5a..79ff437a1 100644 --- a/os/rt/include/chschd.h +++ b/os/rt/include/chschd.h @@ -152,10 +152,7 @@ struct ch_threads_queue { * by shrinking this structure. */ struct ch_thread { - thread_t *next; /**< @brief Next in the list/queue. */ - /* End of the fields shared with the threads_list_t structure.*/ - thread_t *prev; /**< @brief Previous in the queue. */ - /* End of the fields shared with the threads_queue_t structure.*/ + threads_queue_t queue; /**< @brief Threads queue header. */ tprio_t prio; /**< @brief Thread priority. */ struct port_context ctx; /**< @brief Processor context. */ #if (CH_CFG_USE_REGISTRY == TRUE) || defined(__DOXYGEN__) @@ -399,7 +396,7 @@ struct ch_system_debug { */ cnt_t lock_cnt; #endif -#if (CH_DBG_TRACE_MASK != CH_DBG_TRACE_MASK_NONE) || defined(__DOXYGEN__) +#if (CH_DBG_TRACE_MASK != CH_DBG_TRACE_MASK_DISABLED) || defined(__DOXYGEN__) /** * @brief Public trace buffer. */ @@ -585,14 +582,14 @@ static inline bool queue_notempty(const threads_queue_t *tqp) { #if CH_CFG_OPTIMIZE_SPEED == TRUE static inline void list_insert(thread_t *tp, threads_list_t *tlp) { - tp->next = tlp->next; + tp->queue.next = tlp->next; tlp->next = tp; } static inline thread_t *list_remove(threads_list_t *tlp) { thread_t *tp = tlp->next; - tlp->next = tp->next; + tlp->next = tp->queue.next; return tp; } @@ -601,27 +598,27 @@ static inline void queue_prio_insert(thread_t *tp, threads_queue_t *tqp) { thread_t *cp = (thread_t *)tqp; do { - cp = cp->next; + cp = cp->queue.next; } while ((cp != (thread_t *)tqp) && (cp->prio >= tp->prio)); - tp->next = cp; - tp->prev = cp->prev; - tp->prev->next = tp; - cp->prev = tp; + tp->queue.next = cp; + tp->queue.prev = cp->queue.prev; + tp->queue.prev->queue.next = tp; + cp->queue.prev = tp; } static inline void queue_insert(thread_t *tp, threads_queue_t *tqp) { - tp->next = (thread_t *)tqp; - tp->prev = tqp->prev; - tp->prev->next = tp; - tqp->prev = tp; + tp->queue.next = (thread_t *)tqp; + tp->queue.prev = tqp->prev; + tp->queue.prev->queue.next = tp; + tqp->prev = tp; } static inline thread_t *queue_fifo_remove(threads_queue_t *tqp) { thread_t *tp = tqp->next; - tqp->next = tp->next; - tqp->next->prev = (thread_t *)tqp; + tqp->next = tp->queue.next; + tqp->next->queue.prev = (thread_t *)tqp; return tp; } @@ -629,16 +626,16 @@ static inline thread_t *queue_fifo_remove(threads_queue_t *tqp) { static inline thread_t *queue_lifo_remove(threads_queue_t *tqp) { thread_t *tp = tqp->prev; - tqp->prev = tp->prev; - tqp->prev->next = (thread_t *)tqp; + tqp->prev = tp->queue.prev; + tqp->prev->queue.next = (thread_t *)tqp; return tp; } static inline thread_t *queue_dequeue(thread_t *tp) { - tp->prev->next = tp->next; - tp->next->prev = tp->prev; + tp->queue.prev->queue.next = tp->queue.next; + tp->queue.next->queue.prev = tp->queue.prev; return tp; } -- cgit v1.2.3