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
This commit is contained in:
Giovanni Di Sirio 2016-04-05 10:07:57 +00:00
parent b529e1b88e
commit fbb8e86676
4 changed files with 53 additions and 56 deletions

View File

@ -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;
}

View File

@ -78,7 +78,7 @@
/**
* @brief Trace buffer entries.
* @note The trace buffer is only allocated if @p CH_DBG_TRACE_MASK is
* different from @p CH_DBG_TRACE_MASK_NONE.
* different from @p CH_DBG_TRACE_MASK_DISABLED.
*/
#if !defined(CH_DBG_TRACE_BUFFER_SIZE) || defined(__DOXYGEN__)
#define CH_DBG_TRACE_BUFFER_SIZE 128
@ -97,7 +97,7 @@
/* Module data structures and types. */
/*===========================================================================*/
#if (CH_DBG_TRACE_MASK != CH_DBG_TRACE_MASK_NONE) || defined(__DOXYGEN__)
#if (CH_DBG_TRACE_MASK != CH_DBG_TRACE_MASK_DISABLED) || defined(__DOXYGEN__)
/*lint -save -e46 [6.1] An uint32_t is required.*/
/**
* @brief Trace buffer record.
@ -191,7 +191,7 @@ typedef struct {
*/
ch_trace_event_t buffer[CH_DBG_TRACE_BUFFER_SIZE];
} ch_trace_buffer_t;
#endif /* CH_DBG_TRACE_MASK != CH_DBG_TRACE_MASK_NONE */
#endif /* CH_DBG_TRACE_MASK != CH_DBG_TRACE_MASK_DISABLED */
/*===========================================================================*/
/* Module macros. */

View File

@ -87,12 +87,12 @@ 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;
}
/**
@ -105,10 +105,10 @@ void queue_prio_insert(thread_t *tp, threads_queue_t *tqp) {
*/
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;
}
/**
@ -124,8 +124,8 @@ void queue_insert(thread_t *tp, threads_queue_t *tqp) {
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;
}
@ -143,8 +143,8 @@ thread_t *queue_fifo_remove(threads_queue_t *tqp) {
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;
}
@ -161,8 +161,8 @@ thread_t *queue_lifo_remove(threads_queue_t *tqp) {
*/
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;
}
@ -177,8 +177,8 @@ thread_t *queue_dequeue(thread_t *tp) {
*/
void list_insert(thread_t *tp, threads_list_t *tlp) {
tp->next = tlp->next;
tlp->next = tp;
tp->queue.next = tlp->next;
tlp->next = tp;
}
/**
@ -193,7 +193,7 @@ void list_insert(thread_t *tp, threads_list_t *tlp) {
thread_t *list_remove(threads_list_t *tlp) {
thread_t *tp = tlp->next;
tlp->next = tp->next;
tlp->next = tp->queue.next;
return tp;
}
@ -227,13 +227,13 @@ thread_t *chSchReadyI(thread_t *tp) {
tp->state = CH_STATE_READY;
cp = (thread_t *)&ch.rlist.queue;
do {
cp = cp->next;
cp = cp->queue.next;
} while (cp->prio >= tp->prio);
/* Insertion on prev.*/
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;
return tp;
}
@ -266,13 +266,13 @@ thread_t *chSchReadyAheadI(thread_t *tp) {
tp->state = CH_STATE_READY;
cp = (thread_t *)&ch.rlist.queue;
do {
cp = cp->next;
cp = cp->queue.next;
} while (cp->prio > tp->prio);
/* Insertion on prev.*/
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;
return tp;
}

View File

@ -118,7 +118,7 @@ void chSysInit(void) {
#if CH_DBG_STATISTICS == TRUE
_stats_init();
#endif
#if CH_DBG_TRACE_MASK != CH_DBG_TRACE_MASK_NONE
#if CH_DBG_TRACE_MASK != CH_DBG_TRACE_MASK_DISABLED
_dbg_trace_init();
#endif
@ -247,14 +247,14 @@ bool chSysIntegrityCheckI(unsigned testmask) {
tp = ch.rlist.queue.next;
while (tp != (thread_t *)&ch.rlist.queue) {
n++;
tp = tp->next;
tp = tp->queue.next;
}
/* Scanning the ready list backward.*/
tp = ch.rlist.queue.prev;
while (tp != (thread_t *)&ch.rlist.queue) {
n--;
tp = tp->prev;
tp = tp->queue.prev;
}
/* The number of elements must match.*/