aboutsummaryrefslogtreecommitdiffstats
path: root/src/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/include')
-rw-r--r--src/include/ch.h16
-rw-r--r--src/include/lists.h67
-rw-r--r--src/include/scheduler.h2
-rw-r--r--src/include/semaphores.h17
-rw-r--r--src/include/threads.h74
5 files changed, 125 insertions, 51 deletions
diff --git a/src/include/ch.h b/src/include/ch.h
index 80204bb2d..aa77df544 100644
--- a/src/include/ch.h
+++ b/src/include/ch.h
@@ -25,8 +25,6 @@
#ifndef _CH_H_
#define _CH_H_
-typedef struct Thread Thread;
-
#ifndef __DOXIGEN__
#ifndef _CHCONF_H_
#include <chconf.h>
@@ -41,14 +39,22 @@ typedef struct Thread Thread;
#endif
#endif /* __DOXIGEN__ */
-#ifndef _DELTA_H_
+#ifndef _LISTS_H_
#include "delta.h"
#endif
+#ifndef _LISTS_H_
+#include "lists.h"
+#endif
+
#ifndef _SCHEDULER_H_
#include "scheduler.h"
#endif
+#ifndef _SEMAPHORES_H_
+#include "semaphores.h"
+#endif
+
#ifndef _EVENTS_H_
#include "events.h"
#endif
@@ -65,10 +71,6 @@ typedef struct Thread Thread;
#include "sleep.h"
#endif
-#ifndef _SEMAPHORES_H_
-#include "semaphores.h"
-#endif
-
#ifndef _QUEUES_H_
#include "queues.h"
#endif
diff --git a/src/include/lists.h b/src/include/lists.h
new file mode 100644
index 000000000..477ab1061
--- /dev/null
+++ b/src/include/lists.h
@@ -0,0 +1,67 @@
+/*
+ ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio.
+
+ This file is part of ChibiOS/RT.
+
+ ChibiOS/RT is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/RT is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/**
+ * @addtogroup Threads
+ * @{
+ */
+
+#ifndef _LISTS_H_
+#define _LISTS_H_
+
+typedef struct Thread Thread;
+
+/* Macros good with both ThreadsQueue and ThreadsList.*/
+#define isempty(p) ((p)->p_next == (Thread *)(p))
+#define notempty(p) ((p)->p_next != (Thread *)(p))
+
+/**
+ * Generic threads FIFO queue header and element.
+ */
+typedef struct {
+ /** Next \p Thread in the queue, in FIFO order.*/
+ Thread *p_next;
+ /** Last \p Thread in the queue, in FIFO order.*/
+ Thread *p_prev;
+} ThreadsQueue;
+
+/**
+ * Generic threads single link list, it works like a stack.
+ */
+typedef struct {
+ Thread *p_next;
+} ThreadsList;
+
+/*
+ * Threads Lists functions and macros.
+ */
+#define fifo_init(tqp) ((tqp)->p_next = (tqp)->p_prev = (Thread *)(tqp));
+#define list_init(tlp) ((tlp)->p_next = (Thread *)(tlp))
+
+#ifndef CH_OPTIMIZE_SPEED
+void fifo_insert(Thread *tp, ThreadsQueue *tqp);
+Thread *fifo_remove(ThreadsQueue *tqp);
+Thread *dequeue(Thread *tp);
+void list_insert(Thread *tp, ThreadsList *tlp);
+Thread *list_remove(ThreadsList *tlp);
+#endif
+
+#endif /* _LISTS_H_ */
+
+/** @} */
diff --git a/src/include/scheduler.h b/src/include/scheduler.h
index 78fbb4a72..2efabbcd2 100644
--- a/src/include/scheduler.h
+++ b/src/include/scheduler.h
@@ -32,6 +32,8 @@
/** Returned if the thread was made ready because a reset.*/
#define RDY_RESET -2
+#define firstprio(qp) ((qp)->p_next->p_prio)
+
/**
* Ready list header.
*/
diff --git a/src/include/semaphores.h b/src/include/semaphores.h
index 83d4613de..8179627f4 100644
--- a/src/include/semaphores.h
+++ b/src/include/semaphores.h
@@ -34,12 +34,12 @@ typedef struct {
/** Queue of the threads sleeping on this Semaphore.*/
ThreadsQueue s_queue;
/** The Semaphore counter.*/
- t_semcnt s_cnt;
+ t_cnt s_cnt;
} Semaphore;
-void chSemInit(Semaphore *sp, t_semcnt n);
-void chSemReset(Semaphore *sp, t_semcnt n);
-void chSemResetI(Semaphore *sp, t_semcnt n);
+void chSemInit(Semaphore *sp, t_cnt n);
+void chSemReset(Semaphore *sp, t_cnt n);
+void chSemResetI(Semaphore *sp, t_cnt n);
void chSemWait(Semaphore *sp);
void chSemWaitS(Semaphore *sp);
t_msg chSemWaitTimeout(Semaphore *sp, t_time time);
@@ -59,21 +59,18 @@ void chSemLowerPrioSignalWait(Semaphore *sps, Semaphore *spw);
* Decreases the semaphore counter, this macro can be used when it is ensured
* that the counter would not become negative.
*/
-#define chSemFastWaitS(sp) \
- ((sp)->s_cnt--)
+#define chSemFastWaitS(sp) ((sp)->s_cnt--)
/**
* Increases the semaphore counter, this macro can be used when the counter is
* not negative.
*/
-#define chSemFastSignalI(sp) \
- ((sp)->s_cnt++)
+#define chSemFastSignalI(sp) ((sp)->s_cnt++)
/**
* Returns the semaphore counter current value.
*/
-#define chSemGetCounter(sp) \
- ((sp)->s_cnt)
+#define chSemGetCounter(sp) ((sp)->s_cnt)
#endif /* CH_USE_SEMAPHORES */
diff --git a/src/include/threads.h b/src/include/threads.h
index 688ce579a..beb41aae7 100644
--- a/src/include/threads.h
+++ b/src/include/threads.h
@@ -25,21 +25,6 @@
#ifndef _THREADS_H_
#define _THREADS_H_
-#define isempty(qp) ((qp)->p_next == (Thread *)(qp))
-#define notempty(qp) ((qp)->p_next != (Thread *)(qp))
-#define firstprio(qp) ((qp)->p_next->p_prio)
-#define lastprio(qp) ((qp)->p_prev->p_prio)
-
-/**
- * Generic threads queue header and element.
- */
-typedef struct {
- /** First \p Thread in the queue.*/
- Thread *p_next;
- /** Last \p Thread in the queue.*/
- Thread *p_prev;
-} ThreadsQueue;
-
/**
* Structure representing a thread.
* @note Not all the listed fields are always needed, by switching off some
@@ -49,6 +34,7 @@ typedef struct {
struct Thread {
/** Next \p Thread in the threads list.*/
Thread *p_next;
+ /* End of the fields shared with the ThreadsList structure. */
/** Previous \p Thread in the threads list.*/
Thread *p_prev;
/* End of the fields shared with the ThreadsQueue structure. */
@@ -66,10 +52,14 @@ struct Thread {
*/
union {
/** Thread wakeup code, normally set to \p RDY_OK by the \p chSchReadyI()
- * (only while in \p PRCURR or \p PRREADY states).*/
+ * (only while in \p PRREADY state).*/
t_msg p_rdymsg;
/** The thread exit code (only while in \p PREXIT state).*/
t_msg p_exitcode;
+#ifdef CH_USE_SEMAPHORES
+ /** Semaphore where the thread is waiting on (only in \p PRWTSEM state).*/
+ Semaphore *p_semp;
+#endif
#ifdef CH_USE_EVENTS
/** Enabled events mask (only while in \p PRWTEVENT state).*/
t_eventmask p_ewmask;
@@ -89,7 +79,7 @@ struct Thread {
*/
#ifdef CH_USE_WAITEXIT
/** The queue of the threads waiting for this thread termination.*/
- ThreadsQueue p_waiting;
+ ThreadsList p_waiting;
#endif
#ifdef CH_USE_EXIT_EVENT
/** The thread termination \p EventSource.*/
@@ -103,9 +93,8 @@ struct Thread {
t_eventmask p_epending;
#endif
#ifdef CH_USE_RT_SEMAPHORES
- /** Priority backup after acquiring a RT semaphore.*/
/** RT semaphores depth counter.*/
- int p_rtcnt;
+ t_cnt p_rtcnt;
#endif
};
@@ -142,13 +131,13 @@ struct Thread {
/** Lowest user priority.*/
#define LOWPRIO 1
/** Normal user priority.*/
-#define NORMALPRIO 128
+#define NORMALPRIO 64
/** Highest user priority.*/
-#define HIGHPRIO 255
+#define HIGHPRIO 127
/** Boosted base priority.*/
-#define MEPRIO 256
-/** Absolute priority.*/
-#define ABSPRIO 512
+#define MEPRIO 128
+/** Greatest possible priority.*/
+#define ABSPRIO 255
/* Not an API, don't use into the application code.*/
void _InitThread(t_prio prio, t_tmode mode, Thread *tp);
@@ -157,12 +146,24 @@ void _InitThread(t_prio prio, t_tmode mode, Thread *tp);
typedef t_msg (*t_tfunc)(void *);
/*
- * Threads Lists functions.
+ * Inlined functions if CH_OPTIMIZE_SPEED is enabled.
*/
-#ifndef CH_OPTIMIZE_SPEED
-void enqueue(Thread *tp, ThreadsQueue *tqp);
-Thread *dequeue(Thread *tp);
-#else
+#ifdef CH_OPTIMIZE_SPEED
+static INLINE void fifo_insert(Thread *tp, ThreadsQueue *tqp) {
+
+ tp->p_next = (Thread *)tqp;
+ tp->p_prev = tqp->p_prev;
+ tqp->p_prev->p_next = tp;
+ tqp->p_prev = tp;
+}
+
+static INLINE Thread *fifo_remove(ThreadsQueue *tqp) {
+ Thread *tp = tqp->p_next;
+
+ (tqp->p_next = tp->p_next)->p_prev = (Thread *)tqp;
+ return tp;
+}
+
static INLINE Thread *dequeue(Thread *tp) {
tp->p_prev->p_next = tp->p_next;
@@ -170,12 +171,17 @@ static INLINE Thread *dequeue(Thread *tp) {
return tp;
}
-static INLINE void enqueue(Thread *tp, ThreadsQueue *tqp) {
+static INLINE void list_insert(Thread *tp, ThreadsList *tlp) {
- tp->p_next = (Thread *)tqp;
- tp->p_prev = tqp->p_prev;
- tqp->p_prev->p_next = tp;
- tqp->p_prev = tp;
+ 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