aboutsummaryrefslogtreecommitdiffstats
path: root/os/kernel/include/chsem.h
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2013-07-19 13:17:42 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2013-07-19 13:17:42 +0000
commitd58064a533743df77e52f9d76385a9e0ea1d0227 (patch)
tree2e76847d1640e8c9f27a0c2fc0bf8ce60ba4b0b4 /os/kernel/include/chsem.h
parent84e044f176cee7c6946b24c36c90f63534b5b369 (diff)
downloadChibiOS-d58064a533743df77e52f9d76385a9e0ea1d0227.tar.gz
ChibiOS-d58064a533743df77e52f9d76385a9e0ea1d0227.tar.bz2
ChibiOS-d58064a533743df77e52f9d76385a9e0ea1d0227.zip
Still work in progress.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@5996 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/kernel/include/chsem.h')
-rw-r--r--os/kernel/include/chsem.h98
1 files changed, 68 insertions, 30 deletions
diff --git a/os/kernel/include/chsem.h b/os/kernel/include/chsem.h
index 649287e7d..78cf8ac37 100644
--- a/os/kernel/include/chsem.h
+++ b/os/kernel/include/chsem.h
@@ -31,34 +31,34 @@
#if CH_USE_SEMAPHORES || defined(__DOXYGEN__)
+/*===========================================================================*/
+/* Module constants. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Module pre-compile time settings. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Module data structures and types. */
+/*===========================================================================*/
+
/**
* @brief Semaphore structure.
*/
-typedef struct Semaphore {
+typedef struct semaphore {
threads_queue_t s_queue; /**< @brief Queue of the threads sleeping
on this semaphore. */
cnt_t s_cnt; /**< @brief The semaphore counter. */
-} Semaphore;
+} semaphore_t;
-#ifdef __cplusplus
-extern "C" {
-#endif
- void chSemInit(Semaphore *sp, cnt_t n);
- void chSemReset(Semaphore *sp, cnt_t n);
- void chSemResetI(Semaphore *sp, cnt_t n);
- msg_t chSemWait(Semaphore *sp);
- msg_t chSemWaitS(Semaphore *sp);
- msg_t chSemWaitTimeout(Semaphore *sp, systime_t time);
- msg_t chSemWaitTimeoutS(Semaphore *sp, systime_t time);
- void chSemSignal(Semaphore *sp);
- void chSemSignalI(Semaphore *sp);
- void chSemAddCounterI(Semaphore *sp, cnt_t n);
-#if CH_USE_SEMSW
- msg_t chSemSignalWait(Semaphore *sps, Semaphore *spw);
-#endif
-#ifdef __cplusplus
-}
-#endif
+/*===========================================================================*/
+/* Module macros. */
+/*===========================================================================*/
/**
* @brief Data part of a static semaphore initializer.
@@ -80,19 +80,48 @@ extern "C" {
* @param[in] n the counter initial value, this value must be
* non-negative
*/
-#define SEMAPHORE_DECL(name, n) Semaphore name = _SEMAPHORE_DATA(name, n)
+#define SEMAPHORE_DECL(name, n) semaphore_t name = _SEMAPHORE_DATA(name, n)
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void chSemInit(semaphore_t *sp, cnt_t n);
+ void chSemReset(semaphore_t *sp, cnt_t n);
+ void chSemResetI(semaphore_t *sp, cnt_t n);
+ msg_t chSemWait(semaphore_t *sp);
+ msg_t chSemWaitS(semaphore_t *sp);
+ msg_t chSemWaitTimeout(semaphore_t *sp, systime_t time);
+ msg_t chSemWaitTimeoutS(semaphore_t *sp, systime_t time);
+ void chSemSignal(semaphore_t *sp);
+ void chSemSignalI(semaphore_t *sp);
+ void chSemAddCounterI(semaphore_t *sp, cnt_t n);
+#if CH_USE_SEMSW
+ msg_t chSemSignalWait(semaphore_t *sps, semaphore_t *spw);
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+/*===========================================================================*/
+/* Module inline functions. */
+/*===========================================================================*/
-/**
- * @name Macro Functions
- * @{
- */
/**
* @brief Decreases the semaphore counter.
* @details This macro can be used when the counter is known to be positive.
*
* @iclass
*/
-#define chSemFastWaitI(sp) ((sp)->s_cnt--)
+static inline void chSemFastWaitI(semaphore_t *sp) {
+
+ chDbgCheckClassI();
+
+ sp->s_cnt--;
+}
/**
* @brief Increases the semaphore counter.
@@ -101,15 +130,24 @@ extern "C" {
*
* @iclass
*/
-#define chSemFastSignalI(sp) ((sp)->s_cnt++)
+static inline void chSemFastSignalI(semaphore_t *sp) {
+
+ chDbgCheckClassI();
+
+ sp->s_cnt++;
+}
/**
* @brief Returns the semaphore counter current value.
*
* @iclass
*/
-#define chSemGetCounterI(sp) ((sp)->s_cnt)
-/** @} */
+static inline cnt_t chSemGetCounterI(semaphore_t *sp) {
+
+ chDbgCheckClassI();
+
+ return sp->s_cnt;
+}
#endif /* CH_USE_SEMAPHORES */