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