diff options
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/ch.h | 4 | ||||
-rw-r--r-- | src/include/mutexes.h | 66 | ||||
-rw-r--r-- | src/include/semaphores.h | 9 | ||||
-rw-r--r-- | src/include/threads.h | 26 |
4 files changed, 86 insertions, 19 deletions
diff --git a/src/include/ch.h b/src/include/ch.h index be251415f..2c2bb2f7c 100644 --- a/src/include/ch.h +++ b/src/include/ch.h @@ -57,6 +57,10 @@ #include "semaphores.h"
#endif
+#ifndef _MUTEXES_H_
+#include "mutexes.h"
+#endif
+
#ifndef _EVENTS_H_
#include "events.h"
#endif
diff --git a/src/include/mutexes.h b/src/include/mutexes.h new file mode 100644 index 000000000..e2881423d --- /dev/null +++ b/src/include/mutexes.h @@ -0,0 +1,66 @@ +/*
+ 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 Mutexes
+ * @{
+ */
+
+#ifndef _MUTEXES_H_
+#define _MUTEXES_H_
+
+#ifdef CH_USE_MUTEXES
+
+typedef struct Mutex Mutex;
+
+struct Mutex {
+ /** Queue of the threads sleeping on this Mutex.*/
+ ThreadsQueue m_queue;
+ /** Owner \p Thread pointer or \p NULL.*/
+ Thread *m_owner;
+ /** Next \p Mutex into an owner-list, \p NULL if none.*/
+ Mutex *m_next;
+};
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void chMtxInit(Mutex *mp);
+ void chMtxLock(Mutex *mp);
+ void chMtxLockS(Mutex *mp);
+ BOOL chMtxTryLock(Mutex *mp);
+ BOOL chMtxTryLockS(Mutex *mp);
+ void chMtxUnlock(void);
+ void chMtxUnlockS(void);
+ void chMtxUnlockAll(void);
+ void chMtxUnlockAllS(void);
+#ifdef __cplusplus
+}
+#endif
+
+/**
+ * Returns \p TRUE if the mutex queus contains at least a waiting thread.
+ */
+#define chMtxQueueNotEmptyS(mp) notempty(&(mp)->m_queue)
+
+#endif /* CH_USE_MUTEXES */
+
+#endif /* _MUTEXES_H_ */
+
+/** @} */
diff --git a/src/include/semaphores.h b/src/include/semaphores.h index e17d03a6a..0457da81d 100644 --- a/src/include/semaphores.h +++ b/src/include/semaphores.h @@ -52,13 +52,6 @@ extern "C" { void chSemSignal(Semaphore *sp);
void chSemSignalI(Semaphore *sp);
void chSemSignalWait(Semaphore *sps, Semaphore *spw);
-
-#ifdef CH_USE_RT_SEMAPHORES
- void chSemRaisePrioWait(Semaphore *sp);
- void chSemLowerPrioSignal(Semaphore *sp);
- void chSemRaisePrioSignalWait(Semaphore *sps, Semaphore *spw);
- void chSemLowerPrioSignalWait(Semaphore *sps, Semaphore *spw);
-#endif
#ifdef __cplusplus
}
#endif
@@ -82,6 +75,6 @@ extern "C" { #endif /* CH_USE_SEMAPHORES */
-#endif /* _SEM_H_ */
+#endif /* _SEMAPHORES_H_ */
/** @} */
diff --git a/src/include/threads.h b/src/include/threads.h index 0783c4e9a..241b44442 100644 --- a/src/include/threads.h +++ b/src/include/threads.h @@ -62,6 +62,9 @@ struct Thread { /** Semaphore where the thread is waiting on (only in \p PRWTSEM state).*/
Semaphore *p_semp;
#endif
+#ifdef CH_USE_MUTEXES
+ Mutex *p_mtxp;
+#endif
#ifdef CH_USE_EVENTS
/** Enabled events mask (only while in \p PRWTEVENT state).*/
t_eventmask p_ewmask;
@@ -96,9 +99,10 @@ struct Thread { /** Pending events mask.*/
t_eventmask p_epending;
#endif
-#ifdef CH_USE_RT_SEMAPHORES
- /** RT semaphores depth counter.*/
- t_cnt p_rtcnt;
+#ifdef CH_USE_MUTEXES
+ /** Owner mutexes list, \p NULL terminated.*/
+ Mutex *p_mtxlist;
+ t_prio p_realprio;
#endif
};
@@ -112,18 +116,20 @@ struct Thread { #define PRSUSPENDED 3
/** Thread state: Waiting on a semaphore.*/
#define PRWTSEM 4
+/** Thread state: Waiting on a mutex.*/
+#define PRWTMTX 5
/** Thread state: Waiting in \p chThdSleep() or \p chThdSleepUntil().*/
-#define PRSLEEP 5
+#define PRSLEEP 6
/** Thread state: Waiting in \p chThdWait().*/
-#define PRWAIT 6
+#define PRWAIT 7
/** Thread state: Waiting in \p chEvtWait().*/
-#define PRWTEVENT 7
+#define PRWTEVENT 8
/** Thread state: Waiting in \p chMsgSend().*/
-#define PRSNDMSG 8
+#define PRSNDMSG 9
/** Thread state: Waiting in \p chMsgWait().*/
-#define PRWTMSG 9
+#define PRWTMSG 10
/** Thread state: After termination.*/
-#define PREXIT 10
+#define PREXIT 11
/** Thread option: Termination requested flag.*/
#define P_TERMINATE 1
@@ -138,8 +144,6 @@ struct Thread { #define NORMALPRIO 64
/** Highest user priority.*/
#define HIGHPRIO 127
-/** Boosted base priority.*/
-#define MEPRIO 128
/** Greatest possible priority.*/
#define ABSPRIO 255
|