1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
/*
ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio.
This file is part of ChibiOS.
ChibiOS is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
ChibiOS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file oslib/include/chdelegates.h
* @brief Delegate threads macros and structures.
*
* @addtogroup oslib_delegates
* @{
*/
#ifndef CHDELEGATES_H
#define CHDELEGATES_H
#if (CH_CFG_USE_DELEGATES == TRUE) || defined(__DOXYGEN__)
/*lint -save -e829 [17.1] Required by design.*/
#include <stdarg.h>
/*lint -restore*/
/*===========================================================================*/
/* Module constants. */
/*===========================================================================*/
/*===========================================================================*/
/* Module pre-compile time settings. */
/*===========================================================================*/
/*===========================================================================*/
/* Derived constants and error checks. */
/*===========================================================================*/
#if CH_CFG_USE_MESSAGES == FALSE
#error "CH_CFG_USE_DELEGATES requires CH_CFG_USE_MESSAGES"
#endif
/*===========================================================================*/
/* Module data structures and types. */
/*===========================================================================*/
/**
* @brief Type of a delegate veneer function.
*/
typedef msg_t (*delegate_veneer_t)(va_list *argsp);
/**
* @brief Type of a delegate function with no parameters.
*/
typedef msg_t (*delegate_fn0_t)(void);
/**
* @brief Type of a delegate function with one parameter.
*/
typedef msg_t (*delegate_fn1_t)(msg_t p1);
/**
* @brief Type of a delegate function with two parameters.
*/
typedef msg_t (*delegate_fn2_t)(msg_t p1, msg_t p2);
/**
* @brief Type of a delegate function with three parameters.
*/
typedef msg_t (*delegate_fn3_t)(msg_t p1, msg_t p2, msg_t p3);
/**
* @brief Type of a delegate function with four parameters.
*/
typedef msg_t (*delegate_fn4_t)(msg_t p1, msg_t p2, msg_t p3, msg_t p4);
/*===========================================================================*/
/* Module macros. */
/*===========================================================================*/
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
#ifdef __cplusplus
extern "C" {
#endif
msg_t __ch_delegate_fn0(va_list *argsp);
msg_t __ch_delegate_fn1(va_list *argsp);
msg_t __ch_delegate_fn2(va_list *argsp);
msg_t __ch_delegate_fn3(va_list *argsp);
msg_t __ch_delegate_fn4(va_list *argsp);
void chDelegateDispatch(void);
msg_t chDelegateDispatchTimeout(sysinterval_t timeout);
msg_t chDelegateCallVeneer(thread_t *tp, delegate_veneer_t veneer, ...);
#ifdef __cplusplus
}
#endif
/*===========================================================================*/
/* Module inline functions. */
/*===========================================================================*/
/**
* @brief Direct call to a function with no parameters.
* @note The return value is assumed to be not larger than a data
* pointer type. If you need a portable function then use
* @p chDelegateCallVeneer() instead.
*
* @param[in] tp pointer to the delegate thread
* @param[in] func pointer to the function to be called
* @return The function return value as a @p msg_t.
*/
static inline msg_t chDelegateCallDirect0(thread_t *tp, delegate_fn0_t func) {
return chDelegateCallVeneer(tp, __ch_delegate_fn0, func);
}
/**
* @brief Direct call to a function with one parameter.
* @note The return value and parameters are assumed to be not larger
* than a data pointer type. If you need a portable function then use
* @p chDelegateCallVeneer() instead.
*
* @param[in] tp pointer to the delegate thread
* @param[in] func pointer to the function to be called
* @param[in] p1 parameter 1 passed as a @p msg_t
* @return The function return value as a @p msg_t.
*/
static inline msg_t chDelegateCallDirect1(thread_t *tp, delegate_fn1_t func,
msg_t p1) {
return chDelegateCallVeneer(tp, __ch_delegate_fn1, func, p1);
}
/**
* @brief Direct call to a function with two parameters.
* @note The return value and parameters are assumed to be not larger
* than a data pointer type. If you need a portable function then use
* @p chDelegateCallVeneer() instead.
*
* @param[in] tp pointer to the delegate thread
* @param[in] func pointer to the function to be called
* @param[in] p1 parameter 1 passed as a @p msg_t
* @param[in] p2 parameter 2 passed as a @p msg_t
* @return The function return value as a @p msg_t.
*/
static inline msg_t chDelegateCallDirect2(thread_t *tp, delegate_fn2_t func,
msg_t p1, msg_t p2) {
return chDelegateCallVeneer(tp, __ch_delegate_fn2, func, p1, p2);
}
/**
* @brief Direct call to a function with three parameters.
* @note The return value and parameters are assumed to be not larger
* than a data pointer type. If you need a portable function then use
* @p chDelegateCallVeneer() instead.
*
* @param[in] tp pointer to the delegate thread
* @param[in] func pointer to the function to be called
* @param[in] p1 parameter 1 passed as a @p msg_t
* @param[in] p2 parameter 2 passed as a @p msg_t
* @param[in] p3 parameter 3 passed as a @p msg_t
* @return The function return value as a @p msg_t.
*/
static inline msg_t chDelegateCallDirect3(thread_t *tp, delegate_fn3_t func,
msg_t p1, msg_t p2, msg_t p3) {
return chDelegateCallVeneer(tp, __ch_delegate_fn3, func, p1, p2, p3);
}
/**
* @brief Direct call to a function with four parameters.
* @note The return value and parameters are assumed to be not larger
* than a data pointer type. If you need a portable function then use
* @p chDelegateCallVeneer() instead.
*
* @param[in] tp pointer to the delegate thread
* @param[in] func pointer to the function to be called
* @param[in] p1 parameter 1 passed as a @p msg_t
* @param[in] p2 parameter 2 passed as a @p msg_t
* @param[in] p3 parameter 3 passed as a @p msg_t
* @param[in] p4 parameter 4 passed as a @p msg_t
* @return The function return value as a @p msg_t.
*/
static inline msg_t chDelegateCallDirect4(thread_t *tp, delegate_fn4_t func,
msg_t p1, msg_t p2, msg_t p3,
msg_t p4) {
return chDelegateCallVeneer(tp, __ch_delegate_fn4, func, p1, p2, p3, p4);
}
#endif /* CH_CFG_USE_DELEGATES == TRUE */
#endif /* CHDELEGATES_H */
/** @} */
|