aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/chlists.c19
-rw-r--r--src/chmsg.c8
-rw-r--r--src/chschd.c7
-rw-r--r--src/chsem.c8
-rw-r--r--src/include/inline.h9
-rw-r--r--src/include/lists.h3
6 files changed, 37 insertions, 17 deletions
diff --git a/src/chlists.c b/src/chlists.c
index 3b173c94d..dcb3b0412 100644
--- a/src/chlists.c
+++ b/src/chlists.c
@@ -47,19 +47,19 @@ void prio_insert(Thread *tp, ThreadsQueue *tqp) {
}
/*
- * Inserts a Thread into a FIFO queue.
+ * Inserts a Thread into a queue.
*
* @param tp the pointer to the thread to be inserted in the list
* @param tqp the pointer to the threads list header
*/
-void fifo_insert(Thread *tp, ThreadsQueue *tqp) {
+void queue_insert(Thread *tp, ThreadsQueue *tqp) {
tp->p_prev = (tp->p_next = (Thread *)tqp)->p_prev;
tp->p_prev->p_next = tqp->p_prev = tp;
}
/*
- * Removes the first-out Thread from a FIFO queue and returns it.
+ * Removes the first-out Thread from a queue and returns it.
*
* @param tqp the pointer to the threads list header
* @return the removed thread pointer
@@ -72,6 +72,19 @@ Thread *fifo_remove(ThreadsQueue *tqp) {
}
/*
+ * Removes the last-out Thread from a queue and returns it.
+ *
+ * @param tqp the pointer to the threads list header
+ * @return the removed thread pointer
+ */
+Thread *lifo_remove(ThreadsQueue *tqp) {
+ Thread *tp = tqp->p_next;
+
+ (tqp->p_next = tp->p_next)->p_prev = (Thread *)tqp;
+ return tp;
+}
+
+/*
* Removes a Thread from a FIFO list and returns it.
*
* @param tp the pointer to the thread to be removed from the list
diff --git a/src/chmsg.c b/src/chmsg.c
index bcc7117e2..03b7edd01 100644
--- a/src/chmsg.c
+++ b/src/chmsg.c
@@ -40,9 +40,9 @@ msg_t chMsgSend(Thread *tp, msg_t msg) {
if (tp->p_flags & P_MSGBYPRIO)
prio_insert(currp, &tp->p_msgqueue);
else
- fifo_insert(currp, &tp->p_msgqueue);
+ queue_insert(currp, &tp->p_msgqueue);
#else
- fifo_insert(currp, &tp->p_msgqueue);
+ queue_insert(currp, &tp->p_msgqueue);
#endif
currp->p_msg = msg;
currp->p_wtthdp = tp;
@@ -79,9 +79,9 @@ msg_t chMsgSendWithEvent(Thread *tp, msg_t msg, EventSource *esp) {
if (tp->p_flags & P_MSGBYPRIO)
prio_insert(currp, &tp->p_msgqueue);
else
- fifo_insert(currp, &tp->p_msgqueue);
+ queue_insert(currp, &tp->p_msgqueue);
#else
- fifo_insert(currp, &tp->p_msgqueue);
+ queue_insert(currp, &tp->p_msgqueue);
#endif
chEvtBroadcastI(esp);
currp->p_wtthdp = tp;
diff --git a/src/chschd.c b/src/chschd.c
index c97eea1e8..8b606cd1b 100644
--- a/src/chschd.c
+++ b/src/chschd.c
@@ -174,18 +174,17 @@ void chSchWakeupS(Thread *ntp, msg_t msg) {
* Intended to be called if \p chSchRescRequired() evaluates to \p TRUE.
*/
void chSchDoRescheduleI(void) {
- /* put the running thread on the ready queue */
+
Thread *otp = currp;
- chSchReadyI(otp);
- /* pick the first thread from the ready queue */
+ /* pick the first thread from the ready queue and makes it current */
(currp = fifo_remove(&rlist.r_queue))->p_state = PRCURR;
+ chSchReadyI(otp);
#ifdef CH_USE_ROUNDROBIN
rlist.r_preempt = CH_TIME_QUANTUM;
#endif
#ifdef CH_USE_TRACE
chDbgTrace(otp, currp);
#endif
- /* switch thread context */
chSysSwitchI(otp, currp);
}
diff --git a/src/chsem.c b/src/chsem.c
index d1199f072..b5c197b6b 100644
--- a/src/chsem.c
+++ b/src/chsem.c
@@ -72,7 +72,7 @@ void chSemResetI(Semaphore *sp, cnt_t n) {
cnt = sp->s_cnt;
sp->s_cnt = n;
while (cnt++ < 0)
- chSchReadyI(fifo_remove(&sp->s_queue))->p_rdymsg = RDY_RESET;
+ chSchReadyI(lifo_remove(&sp->s_queue))->p_rdymsg = RDY_RESET;
}
/**
@@ -101,7 +101,7 @@ msg_t chSemWait(Semaphore *sp) {
msg_t chSemWaitS(Semaphore *sp) {
if (--sp->s_cnt < 0) {
- fifo_insert(currp, &sp->s_queue);
+ queue_insert(currp, &sp->s_queue);
currp->p_wtsemp = sp;
chSchGoSleepS(PRWTSEM);
return currp->p_rdymsg;
@@ -140,7 +140,7 @@ msg_t chSemWaitTimeout(Semaphore *sp, systime_t time) {
msg_t chSemWaitTimeoutS(Semaphore *sp, systime_t time) {
if (--sp->s_cnt < 0) {
- fifo_insert(currp, &sp->s_queue);
+ queue_insert(currp, &sp->s_queue);
currp->p_wtsemp = sp;
return chSchGoSleepTimeoutS(PRWTSEM, time);
}
@@ -201,7 +201,7 @@ msg_t chSemSignalWait(Semaphore *sps, Semaphore *spw) {
chSchReadyI(fifo_remove(&sps->s_queue))->p_rdymsg = RDY_OK;
if (--spw->s_cnt < 0) {
- fifo_insert(currp, &spw->s_queue);
+ queue_insert(currp, &spw->s_queue);
currp->p_wtsemp = spw;
chSchGoSleepS(PRWTSEM);
msg = currp->p_rdymsg;
diff --git a/src/include/inline.h b/src/include/inline.h
index 85de20f3f..9cc18974d 100644
--- a/src/include/inline.h
+++ b/src/include/inline.h
@@ -36,7 +36,7 @@ static INLINE void prio_insert(Thread *tp, ThreadsQueue *tqp) {
tp->p_prev->p_next = cp->p_prev = tp;
}
-static INLINE void fifo_insert(Thread *tp, ThreadsQueue *tqp) {
+static INLINE void queue_insert(Thread *tp, ThreadsQueue *tqp) {
tp->p_prev = (tp->p_next = (Thread *)tqp)->p_prev;
tp->p_prev->p_next = tqp->p_prev = tp;
@@ -49,6 +49,13 @@ static INLINE Thread *fifo_remove(ThreadsQueue *tqp) {
return tp;
}
+static INLINE Thread *lifo_remove(ThreadsQueue *tqp) {
+ Thread *tp = tqp->p_prev;
+
+ (tqp->p_prev = tp->p_prev)->p_next = (Thread *)tqp;
+ return tp;
+}
+
static INLINE Thread *dequeue(Thread *tp) {
tp->p_prev->p_next = tp->p_next;
diff --git a/src/include/lists.h b/src/include/lists.h
index d98892600..741648a03 100644
--- a/src/include/lists.h
+++ b/src/include/lists.h
@@ -61,8 +61,9 @@ typedef struct {
extern "C" {
#endif
void prio_insert(Thread *tp, ThreadsQueue *tqp);
- void fifo_insert(Thread *tp, ThreadsQueue *tqp);
+ void queue_insert(Thread *tp, ThreadsQueue *tqp);
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);