123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- #ifndef CHSEM_H
- #define CHSEM_H
- #if (CH_CFG_USE_SEMAPHORES == TRUE) || defined(__DOXYGEN__)
- typedef struct ch_semaphore {
- threads_queue_t queue;
- cnt_t cnt;
- } semaphore_t;
- #define _SEMAPHORE_DATA(name, n) {_THREADS_QUEUE_DATA(name.queue), n}
- #define SEMAPHORE_DECL(name, n) semaphore_t name = _SEMAPHORE_DATA(name, n)
- #ifdef __cplusplus
- extern "C" {
- #endif
- void chSemObjectInit(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, sysinterval_t timeout);
- msg_t chSemWaitTimeoutS(semaphore_t *sp, sysinterval_t timeout);
- void chSemSignal(semaphore_t *sp);
- void chSemSignalI(semaphore_t *sp);
- void chSemAddCounterI(semaphore_t *sp, cnt_t n);
- msg_t chSemSignalWait(semaphore_t *sps, semaphore_t *spw);
- #ifdef __cplusplus
- }
- #endif
- static inline void chSemFastWaitI(semaphore_t *sp) {
- chDbgCheckClassI();
- sp->cnt--;
- }
- static inline void chSemFastSignalI(semaphore_t *sp) {
- chDbgCheckClassI();
- sp->cnt++;
- }
- static inline cnt_t chSemGetCounterI(const semaphore_t *sp) {
- chDbgCheckClassI();
- return sp->cnt;
- }
- #endif
- #endif
|