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