ChibiOS/RT 7.0.6
chdelegates.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/**
20 * @file oslib/include/chdelegates.h
21 * @brief Delegate threads macros and structures.
22 *
23 * @addtogroup oslib_delegates
24 * @{
25 */
26
27#ifndef CHDELEGATES_H
28#define CHDELEGATES_H
29
30#if (CH_CFG_USE_DELEGATES == TRUE) || defined(__DOXYGEN__)
31
32/*lint -save -e829 [17.1] Required by design.*/
33#include <stdarg.h>
34/*lint -restore*/
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_MESSAGES == FALSE
49#error "CH_CFG_USE_DELEGATES requires CH_CFG_USE_MESSAGES"
50#endif
51
52/*===========================================================================*/
53/* Module data structures and types. */
54/*===========================================================================*/
55
56/**
57 * @brief Type of a delegate veneer function.
58 */
59typedef msg_t (*delegate_veneer_t)(va_list *argsp);
60
61/**
62 * @brief Type of a delegate function with no parameters.
63 */
64typedef msg_t (*delegate_fn0_t)(void);
65
66/**
67 * @brief Type of a delegate function with one parameter.
68 */
69typedef msg_t (*delegate_fn1_t)(msg_t p1);
70
71/**
72 * @brief Type of a delegate function with two parameters.
73 */
74typedef msg_t (*delegate_fn2_t)(msg_t p1, msg_t p2);
75
76/**
77 * @brief Type of a delegate function with three parameters.
78 */
79typedef msg_t (*delegate_fn3_t)(msg_t p1, msg_t p2, msg_t p3);
80
81/**
82 * @brief Type of a delegate function with four parameters.
83 */
84typedef msg_t (*delegate_fn4_t)(msg_t p1, msg_t p2, msg_t p3, msg_t p4);
85
86/*===========================================================================*/
87/* Module macros. */
88/*===========================================================================*/
89
90/*===========================================================================*/
91/* External declarations. */
92/*===========================================================================*/
93
94#ifdef __cplusplus
95extern "C" {
96#endif
97 msg_t __ch_delegate_fn0(va_list *argsp);
98 msg_t __ch_delegate_fn1(va_list *argsp);
99 msg_t __ch_delegate_fn2(va_list *argsp);
100 msg_t __ch_delegate_fn3(va_list *argsp);
101 msg_t __ch_delegate_fn4(va_list *argsp);
102 void chDelegateDispatch(void);
105#ifdef __cplusplus
106}
107#endif
108
109/*===========================================================================*/
110/* Module inline functions. */
111/*===========================================================================*/
112
113/**
114 * @brief Direct call to a function with no parameters.
115 * @note The return value is assumed to be not larger than a data
116 * pointer type. If you need a portable function then use
117 * @p chDelegateCallVeneer() instead.
118 *
119 * @param[in] tp pointer to the delegate thread
120 * @param[in] func pointer to the function to be called
121 * @return The function return value as a @p msg_t.
122 */
124
125 return chDelegateCallVeneer(tp, __ch_delegate_fn0, func);
126}
127
128/**
129 * @brief Direct call to a function with one parameter.
130 * @note The return value and parameters are assumed to be not larger
131 * than a data pointer type. If you need a portable function then use
132 * @p chDelegateCallVeneer() instead.
133 *
134 * @param[in] tp pointer to the delegate thread
135 * @param[in] func pointer to the function to be called
136 * @param[in] p1 parameter 1 passed as a @p msg_t
137 * @return The function return value as a @p msg_t.
138 */
140 msg_t p1) {
141
142 return chDelegateCallVeneer(tp, __ch_delegate_fn1, func, p1);
143}
144
145/**
146 * @brief Direct call to a function with two parameters.
147 * @note The return value and parameters are assumed to be not larger
148 * than a data pointer type. If you need a portable function then use
149 * @p chDelegateCallVeneer() instead.
150 *
151 * @param[in] tp pointer to the delegate thread
152 * @param[in] func pointer to the function to be called
153 * @param[in] p1 parameter 1 passed as a @p msg_t
154 * @param[in] p2 parameter 2 passed as a @p msg_t
155 * @return The function return value as a @p msg_t.
156 */
158 msg_t p1, msg_t p2) {
159
160 return chDelegateCallVeneer(tp, __ch_delegate_fn2, func, p1, p2);
161}
162
163/**
164 * @brief Direct call to a function with three parameters.
165 * @note The return value and parameters are assumed to be not larger
166 * than a data pointer type. If you need a portable function then use
167 * @p chDelegateCallVeneer() instead.
168 *
169 * @param[in] tp pointer to the delegate thread
170 * @param[in] func pointer to the function to be called
171 * @param[in] p1 parameter 1 passed as a @p msg_t
172 * @param[in] p2 parameter 2 passed as a @p msg_t
173 * @param[in] p3 parameter 3 passed as a @p msg_t
174 * @return The function return value as a @p msg_t.
175 */
177 msg_t p1, msg_t p2, msg_t p3) {
178
179 return chDelegateCallVeneer(tp, __ch_delegate_fn3, func, p1, p2, p3);
180}
181
182/**
183 * @brief Direct call to a function with four parameters.
184 * @note The return value and parameters are assumed to be not larger
185 * than a data pointer type. If you need a portable function then use
186 * @p chDelegateCallVeneer() instead.
187 *
188 * @param[in] tp pointer to the delegate thread
189 * @param[in] func pointer to the function to be called
190 * @param[in] p1 parameter 1 passed as a @p msg_t
191 * @param[in] p2 parameter 2 passed as a @p msg_t
192 * @param[in] p3 parameter 3 passed as a @p msg_t
193 * @param[in] p4 parameter 4 passed as a @p msg_t
194 * @return The function return value as a @p msg_t.
195 */
197 msg_t p1, msg_t p2, msg_t p3,
198 msg_t p4) {
199
200 return chDelegateCallVeneer(tp, __ch_delegate_fn4, func, p1, p2, p3, p4);
201}
202
203#endif /* CH_CFG_USE_DELEGATES == TRUE */
204
205#endif /* CHDELEGATES_H */
206
207/** @} */
int32_t msg_t
Definition chearly.h:87
struct ch_thread thread_t
Type of a thread structure.
Definition chearly.h:132
msg_t __ch_delegate_fn3(va_list *argsp)
Veneer for functions with three parameters.
msg_t __ch_delegate_fn4(va_list *argsp)
Veneer for functions with four parameters.
static msg_t chDelegateCallDirect3(thread_t *tp, delegate_fn3_t func, msg_t p1, msg_t p2, msg_t p3)
Direct call to a function with three parameters.
msg_t(* delegate_fn4_t)(msg_t p1, msg_t p2, msg_t p3, msg_t p4)
Type of a delegate function with four parameters.
Definition chdelegates.h:84
msg_t(* delegate_fn1_t)(msg_t p1)
Type of a delegate function with one parameter.
Definition chdelegates.h:69
static msg_t chDelegateCallDirect1(thread_t *tp, delegate_fn1_t func, msg_t p1)
Direct call to a function with one parameter.
msg_t(* delegate_fn0_t)(void)
Type of a delegate function with no parameters.
Definition chdelegates.h:64
msg_t(* delegate_fn3_t)(msg_t p1, msg_t p2, msg_t p3)
Type of a delegate function with three parameters.
Definition chdelegates.h:79
msg_t chDelegateDispatchTimeout(sysinterval_t timeout)
Call messages dispatching with timeout.
msg_t __ch_delegate_fn0(va_list *argsp)
Veneer for functions with no parameters.
Definition chdelegates.c:87
msg_t chDelegateCallVeneer(thread_t *tp, delegate_veneer_t veneer,...)
Triggers a function call on a delegate thread.
msg_t(* delegate_fn2_t)(msg_t p1, msg_t p2)
Type of a delegate function with two parameters.
Definition chdelegates.h:74
static msg_t chDelegateCallDirect4(thread_t *tp, delegate_fn4_t func, msg_t p1, msg_t p2, msg_t p3, msg_t p4)
Direct call to a function with four parameters.
msg_t __ch_delegate_fn2(va_list *argsp)
Veneer for functions with two parameters.
msg_t __ch_delegate_fn1(va_list *argsp)
Veneer for functions with one parameter.
Definition chdelegates.c:98
msg_t(* delegate_veneer_t)(va_list *argsp)
Type of a delegate veneer function.
Definition chdelegates.h:59
static msg_t chDelegateCallDirect2(thread_t *tp, delegate_fn2_t func, msg_t p1, msg_t p2)
Direct call to a function with two parameters.
void chDelegateDispatch(void)
Call messages dispatching.
static msg_t chDelegateCallDirect0(thread_t *tp, delegate_fn0_t func)
Direct call to a function with no parameters.
uint64_t sysinterval_t
Type of time interval.
Definition chtime.h:118