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-d51de3d6d3f4master
parent
2f39b6e6b5
commit
2706d240bb
|
@ -84,16 +84,16 @@ Win32-MinGW - ChibiOS/RT simulator and demo into a WIN32 process,
|
|||
- NEW: Abstract I/O Channels mechanism introduced. This mechanism allows to
|
||||
access I/O resources through a standard interface and hides implementation
|
||||
details. The existing serial drivers were modified to offer a standard
|
||||
channel interface to the applications.
|
||||
channel interface to the applications (the old APIs are retained as macros).
|
||||
- NEW: The I/O queues code was improved, now there are 2 separate structures:
|
||||
InputQueue and OutputQueue. There are some changes in the queue APIs
|
||||
in order to make them more symmetrical and functional. Improved the queues
|
||||
documentation. Some of the changes were needed in order to support the new
|
||||
channels mechanism as a backend for queued serial drivers.
|
||||
- NEW: Added test cases for the improved queues.
|
||||
- NEW: Added a code coverage analysis application under ./tests/coverage.
|
||||
- NEW: Added more test cases in order to improve the test suite code coverage
|
||||
(it was 74% in version 1.2.0, it is now close to 100%).
|
||||
- NEW: Added test cases for the improved queues and serial drivers.
|
||||
- NEW: Added a code coverage analysis application under ./tests/coverage.
|
||||
- NEW: Added the test suite documentation to the general documentation.
|
||||
- NEW: Added a new "naked" context switch benchmark that better defines the
|
||||
real context switch time, previous benchmarks introduced too much overhead
|
||||
|
|
|
@ -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_ */
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -29,10 +29,37 @@
|
|||
|
||||
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))
|
||||
|
||||
/**
|
||||
* Macro evaluating to @p TRUE if the specified threads queue is not empty.
|
||||
*/
|
||||
#define notempty(p) ((p)->p_next != (Thread *)(p))
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
#define _THREADSQUEUE_DATA(name) {(Thread *)&name, (Thread *)&name}
|
||||
|
||||
/**
|
||||
* @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 THREADSQUEUE_DECL(name) ThreadsQueue name = _THREADSQUEUE_DATA(name)
|
||||
|
||||
/**
|
||||
* @brief Generic threads bidirectional linked list header and element.
|
||||
* @extends ThreadsList
|
||||
|
@ -44,25 +71,6 @@ typedef struct {
|
|||
@p ThreadQueue when empty.*/
|
||||
} ThreadsQueue;
|
||||
|
||||
/**
|
||||
* @brief Generic threads single linked list.
|
||||
* @details This list behaves like a stack.
|
||||
*/
|
||||
typedef struct {
|
||||
Thread *p_next; /**< Last pushed @p Thread on the stack,
|
||||
or @p ThreadList when empty.*/
|
||||
} ThreadsList;
|
||||
|
||||
/**
|
||||
* Queue initialization.
|
||||
*/
|
||||
#define queue_init(tqp) ((tqp)->p_next = (tqp)->p_prev = (Thread *)(tqp));
|
||||
|
||||
/**
|
||||
* List initialization.
|
||||
*/
|
||||
#define list_init(tlp) ((tlp)->p_next = (Thread *)(tlp))
|
||||
|
||||
#if !CH_OPTIMIZE_SPEED
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -54,7 +54,13 @@
|
|||
|
||||
#define ALLOWED_DELAY MS2ST(5)
|
||||
|
||||
static EventSource es1, es2;
|
||||
/*
|
||||
* Note, the static initializers are not really required because the
|
||||
* variables are explicitly initialized in each test case. It is done in order
|
||||
* to test the macros.
|
||||
*/
|
||||
static EVENTSOURCE_DECL(es1);
|
||||
static EVENTSOURCE_DECL(es2);
|
||||
|
||||
/**
|
||||
* @page test_events_001 Events registration and dispatch
|
||||
|
|
|
@ -63,8 +63,14 @@
|
|||
|
||||
#define ALLOWED_DELAY 5
|
||||
|
||||
static Mutex m1, m2;
|
||||
static CondVar c1;
|
||||
/*
|
||||
* Note, the static initializers are not really required because the
|
||||
* variables are explicitly initialized in each test case. It is done in order
|
||||
* to test the macros.
|
||||
*/
|
||||
static MUTEX_DECL(m1);
|
||||
static MUTEX_DECL(m2);
|
||||
static CONDVAR_DECL(c1);
|
||||
|
||||
/**
|
||||
* @page test_mtx_001 Priority enqueuing test
|
||||
|
|
|
@ -53,7 +53,12 @@
|
|||
|
||||
#define ALLOWED_DELAY MS2ST(5)
|
||||
|
||||
static Semaphore sem1;
|
||||
/*
|
||||
* Note, the static initializers are not really required because the
|
||||
* variables are explicitly initialized in each test case. It is done in order
|
||||
* to test the macros.
|
||||
*/
|
||||
static SEMAPHORE_DECL(sem1, 0);
|
||||
|
||||
/**
|
||||
* @page test_sem_001 Enqueuing test
|
||||
|
|
4
todo.txt
4
todo.txt
|
@ -8,8 +8,8 @@ After 1.2.0:
|
|||
* Abstract I/O channels rather than just serial ports.
|
||||
? Move the serial drivers implementations in library. Better keep the core
|
||||
as compact as possible.
|
||||
X Add tests documentation to the general documentation via doxygen.
|
||||
- Static object initializers.
|
||||
* Add tests documentation to the general documentation via doxygen.
|
||||
X Static object initializers.
|
||||
- Remove any instance of unnamed structures/unions.
|
||||
- Objects registry in the kernel.
|
||||
- OSEK-style simple tasks within the idle thread.
|
||||
|
|
Loading…
Reference in New Issue