ChibiOS/RT  6.0.3
chcond.h
Go to the documentation of this file.
1 /*
2  ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio.
3 
4  This file is part of ChibiOS.
5 
6  ChibiOS is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 3 of the License, or
9  (at your option) any later version.
10 
11  ChibiOS is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 /*
20  Concepts and parts of this file have been contributed by Leon Woestenberg.
21  */
22 
23 /**
24  * @file chcond.h
25  * @brief Condition Variables macros and structures.
26  *
27  * @addtogroup condvars
28  * @{
29  */
30 
31 #ifndef CHCOND_H
32 #define CHCOND_H
33 
34 #if (CH_CFG_USE_CONDVARS == TRUE) || defined(__DOXYGEN__)
35 
36 /*===========================================================================*/
37 /* Module constants. */
38 /*===========================================================================*/
39 
40 /*===========================================================================*/
41 /* Module pre-compile time settings. */
42 /*===========================================================================*/
43 
44 /*===========================================================================*/
45 /* Derived constants and error checks. */
46 /*===========================================================================*/
47 
48 #if CH_CFG_USE_MUTEXES == FALSE
49 #error "CH_CFG_USE_CONDVARS requires CH_CFG_USE_MUTEXES"
50 #endif
51 
52 /*===========================================================================*/
53 /* Module data structures and types. */
54 /*===========================================================================*/
55 
56 /**
57  * @brief condition_variable_t structure.
58  */
59 typedef struct condition_variable {
60  threads_queue_t queue; /**< @brief Condition variable
61  threads queue. */
63 
64 /*===========================================================================*/
65 /* Module macros. */
66 /*===========================================================================*/
67 
68 /**
69  * @brief Data part of a static condition variable initializer.
70  * @details This macro should be used when statically initializing a condition
71  * variable that is part of a bigger structure.
72  *
73  * @param[in] name the name of the condition variable
74  */
75 #define _CONDVAR_DATA(name) {_THREADS_QUEUE_DATA(name.queue)}
76 
77 /**
78  * @brief Static condition variable initializer.
79  * @details Statically initialized condition variables require no explicit
80  * initialization using @p chCondInit().
81  *
82  * @param[in] name the name of the condition variable
83  */
84 #define CONDVAR_DECL(name) condition_variable_t name = _CONDVAR_DATA(name)
85 
86 /*===========================================================================*/
87 /* External declarations. */
88 /*===========================================================================*/
89 
90 #ifdef __cplusplus
91 extern "C" {
92 #endif
100 #if CH_CFG_USE_CONDVARS_TIMEOUT == TRUE
103 #endif
104 #ifdef __cplusplus
105 }
106 #endif
107 
108 /*===========================================================================*/
109 /* Module inline functions. */
110 /*===========================================================================*/
111 
112 #endif /* CH_CFG_USE_CONDVARS == TRUE */
113 
114 #endif /* CHCOND_H */
115 
116 /** @} */
void chCondObjectInit(condition_variable_t *cp)
Initializes s condition_variable_t structure.
Definition: chcond.c:75
void chCondBroadcast(condition_variable_t *cp)
Signals all threads that are waiting on the condition variable.
Definition: chcond.c:130
uint64_t sysinterval_t
Type of time interval.
Definition: chtime.h:119
void chCondSignal(condition_variable_t *cp)
Signals one thread that is waiting on the condition variable.
Definition: chcond.c:89
void chCondSignalI(condition_variable_t *cp)
Signals one thread that is waiting on the condition variable.
Definition: chcond.c:111
Generic threads bidirectional linked list header and element.
Definition: chschd.h:142
msg_t chCondWaitTimeout(condition_variable_t *cp, sysinterval_t timeout)
Waits on the condition variable releasing the mutex lock.
Definition: chcond.c:257
msg_t chCondWait(condition_variable_t *cp)
Waits on the condition variable releasing the mutex lock.
Definition: chcond.c:179
condition_variable_t structure.
Definition: chcond.h:59
msg_t chCondWaitTimeoutS(condition_variable_t *cp, sysinterval_t timeout)
Waits on the condition variable releasing the mutex lock.
Definition: chcond.c:295
struct condition_variable condition_variable_t
condition_variable_t structure.
threads_queue_t queue
Condition variable threads queue.
Definition: chcond.h:60
void chCondBroadcastI(condition_variable_t *cp)
Signals all threads that are waiting on the condition variable.
Definition: chcond.c:149
msg_t chCondWaitS(condition_variable_t *cp)
Waits on the condition variable releasing the mutex lock.
Definition: chcond.c:205