ChibiOS/RT  6.1.4
chcond.h
Go to the documentation of this file.
1 /*
2  ChibiOS - Copyright (C) 2006,2007,2008,2009,2010,2011,2012,2013,2014,
3  2015,2016,2017,2018,2019,2020,2021 Giovanni Di Sirio.
4 
5  This file is part of ChibiOS.
6 
7  ChibiOS is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation version 3 of the License.
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 rt/include/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  ch_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) {_CH_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 /** @} */
chCondSignal
void chCondSignal(condition_variable_t *cp)
Signals one thread that is waiting on the condition variable.
Definition: chcond.c:89
chCondBroadcast
void chCondBroadcast(condition_variable_t *cp)
Signals all threads that are waiting on the condition variable.
Definition: chcond.c:130
chCondSignalI
void chCondSignalI(condition_variable_t *cp)
Signals one thread that is waiting on the condition variable.
Definition: chcond.c:111
condition_variable::queue
ch_queue_t queue
Condition variable threads queue.
Definition: chcond.h:60
chCondWaitTimeout
msg_t chCondWaitTimeout(condition_variable_t *cp, sysinterval_t timeout)
Waits on the condition variable releasing the mutex lock.
Definition: chcond.c:257
chCondWait
msg_t chCondWait(condition_variable_t *cp)
Waits on the condition variable releasing the mutex lock.
Definition: chcond.c:179
condition_variable_t
struct condition_variable condition_variable_t
condition_variable_t structure.
ch_queue
Structure representing a generic bidirectional linked list header and element.
Definition: chlists.h:69
chCondWaitTimeoutS
msg_t chCondWaitTimeoutS(condition_variable_t *cp, sysinterval_t timeout)
Waits on the condition variable releasing the mutex lock.
Definition: chcond.c:295
sysinterval_t
uint64_t sysinterval_t
Type of time interval.
Definition: chtime.h:119
condition_variable
condition_variable_t structure.
Definition: chcond.h:59
chCondBroadcastI
void chCondBroadcastI(condition_variable_t *cp)
Signals all threads that are waiting on the condition variable.
Definition: chcond.c:149
chCondWaitS
msg_t chCondWaitS(condition_variable_t *cp)
Waits on the condition variable releasing the mutex lock.
Definition: chcond.c:205
chCondObjectInit
void chCondObjectInit(condition_variable_t *cp)
Initializes s condition_variable_t structure.
Definition: chcond.c:75