From 2706d240bbea25b21dac8e0bc123de9cb2080a13 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 16 May 2009 10:57:16 +0000 Subject: Added static initializers to thread queues, semaphores, mutexes, condvars and event sources. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@975 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- src/include/condvars.h | 15 +++++++++++++++ src/include/events.h | 16 ++++++++++++++++ src/include/lists.h | 50 +++++++++++++++++++++++++++--------------------- src/include/mutexes.h | 16 ++++++++++++++++ src/include/semaphores.h | 20 ++++++++++++++++++- 5 files changed, 94 insertions(+), 23 deletions(-) (limited to 'src/include') diff --git a/src/include/condvars.h b/src/include/condvars.h index 90c78eccf..d68637f21 100644 --- a/src/include/condvars.h +++ b/src/include/condvars.h @@ -58,6 +58,21 @@ extern "C" { } #endif +/** + * @brief Data part of a static condition variable initializer. + * @details This macro should be used when statically initializing a condition + * variable that is part of a bigger structure. + */ +#define _CONDVAR_DATA(name) {_THREADSQUEUE_DATA(name.c_queue)} + +/** + * @brief Static condition variable initializer. + * @details Statically initialized condition variables require no explicit + * initialization using @p chCondInit(). + * @param name the name of the condition variable + */ +#define CONDVAR_DECL(name) CondVar name = _CONDVAR_DATA(name) + #endif /* CH_USE_CONDVARS && CH_USE_MUTEXES */ #endif /* _CONDVARS_H_ */ diff --git a/src/include/events.h b/src/include/events.h index ada7812d1..6b79553ed 100644 --- a/src/include/events.h +++ b/src/include/events.h @@ -103,6 +103,22 @@ extern "C" { } #endif +/** + * @brief Data part of a static event source initializer. + * @details This macro should be used when statically initializing an event + * source that is part of a bigger structure. + * @param name the name of the event source variable + */ +#define _EVENTSOURCE_DATA(name) {(EventListener *)&name} + +/** + * @brief Static event source initializer. + * @details Statically initialized event sources require no explicit + * initialization using @p chEvtInit(). + * @param name the name of the event source variable + */ +#define EVENTSOURCE_DECL(name) EventSource name = _EVENTSOURCE_DATA(name) + /** * Registers an Event Listener on an Event Source. * @param esp pointer to the @p EventSource structure diff --git a/src/include/lists.h b/src/include/lists.h index 89fdb84a7..3783f8749 100644 --- a/src/include/lists.h +++ b/src/include/lists.h @@ -29,39 +29,47 @@ typedef struct Thread Thread; -/* Macros good with both ThreadsQueue and ThreadsList.*/ +/** + * Threads queue initialization. + */ +#define queue_init(tqp) ((tqp)->p_next = (tqp)->p_prev = (Thread *)(tqp)); + +/** + * Macro evaluating to @p TRUE if the specified threads queue is empty. + */ #define isempty(p) ((p)->p_next == (Thread *)(p)) -#define notempty(p) ((p)->p_next != (Thread *)(p)) /** - * @brief Generic threads bidirectional linked list header and element. - * @extends ThreadsList + * Macro evaluating to @p TRUE if the specified threads queue is not empty. */ -typedef struct { - Thread *p_next; /**< First @p Thread in the queue, or - @p ThreadQueue when empty.*/ - Thread *p_prev; /**< Last @p Thread in the queue, or - @p ThreadQueue when empty.*/ -} ThreadsQueue; +#define notempty(p) ((p)->p_next != (Thread *)(p)) /** - * @brief Generic threads single linked list. - * @details This list behaves like a stack. + * @brief Data part of a static threads queue initializer. + * @details This macro should be used when statically initializing a threads + * queue that is part of a bigger structure. + * @param name the name of the threads queue variable */ -typedef struct { - Thread *p_next; /**< Last pushed @p Thread on the stack, - or @p ThreadList when empty.*/ -} ThreadsList; +#define _THREADSQUEUE_DATA(name) {(Thread *)&name, (Thread *)&name} /** - * Queue initialization. + * @brief Static threads queue initializer. + * @details Statically initialized threads queues require no explicit + * initialization using @p queue_init(). + * @param name the name of the threads queue variable */ -#define queue_init(tqp) ((tqp)->p_next = (tqp)->p_prev = (Thread *)(tqp)); +#define THREADSQUEUE_DECL(name) ThreadsQueue name = _THREADSQUEUE_DATA(name) /** - * List initialization. + * @brief Generic threads bidirectional linked list header and element. + * @extends ThreadsList */ -#define list_init(tlp) ((tlp)->p_next = (Thread *)(tlp)) +typedef struct { + Thread *p_next; /**< First @p Thread in the queue, or + @p ThreadQueue when empty.*/ + Thread *p_prev; /**< Last @p Thread in the queue, or + @p ThreadQueue when empty.*/ +} ThreadsQueue; #if !CH_OPTIMIZE_SPEED @@ -73,8 +81,6 @@ extern "C" { 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); #ifdef __cplusplus } #endif diff --git a/src/include/mutexes.h b/src/include/mutexes.h index 16b59f695..6ef6e48f4 100644 --- a/src/include/mutexes.h +++ b/src/include/mutexes.h @@ -56,6 +56,22 @@ extern "C" { } #endif +/** + * @brief Data part of a static mutex initializer. + * @details This macro should be used when statically initializing a mutex + * that is part of a bigger structure. + * @param name the name of the mutex variable + */ +#define _MUTEX_DATA(name) {_THREADSQUEUE_DATA(name.m_queue), NULL, NULL} + +/** + * @brief Static mutex initializer. + * @details Statically initialized mutexes require no explicit initialization + * using @p chMtxInit(). + * @param name the name of the mutex variable + */ +#define MUTEX_DECL(name) Mutex name = _MUTEX_DATA(name) + /** * Returns @p TRUE if the mutex queue contains at least a waiting thread. */ diff --git a/src/include/semaphores.h b/src/include/semaphores.h index 10f784ffc..833fc5cd2 100644 --- a/src/include/semaphores.h +++ b/src/include/semaphores.h @@ -57,6 +57,24 @@ extern "C" { } #endif +/** + * @brief Data part of a static semaphore initializer. + * @details This macro should be used when statically initializing a semaphore + * that is part of a bigger structure. + * @param name the name of the semaphore variable + * @param n the counter initial value, this value must be non-negative + */ +#define _SEMAPHORE_DATA(name, n) {_THREADSQUEUE_DATA(name.s_queue), n} + +/** + * @brief Static semaphore initializer. + * @details Statically initialized semaphores require no explicit initialization + * using @p chSemInit(). + * @param name the name of the semaphore variable + * @param n the counter initial value, this value must be non-negative + */ +#define SEMAPHORE_DECL(name, n) Semaphore name = _SEMAPHORE_DATA(name, n) + /** * Decreases the semaphore counter, this macro can be used when it is ensured * that the counter would not become negative. @@ -72,7 +90,7 @@ extern "C" { /** * Returns the semaphore counter current value. */ -#define chSemGetCounterI(sp) ((sp)->s_cnt) +#define chSemGetCounterI(sp) ((sp)->s_cnt) #endif /* CH_USE_SEMAPHORES */ -- cgit v1.2.3