-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcoop_config.h
215 lines (189 loc) · 5.08 KB
/
coop_config.h
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
209
210
211
212
213
214
215
/*
* Copyright (c) 2020-2022 Piotr Stolarz
* Lightweight cooperative threads library
*
* Distributed under the 2-clause BSD License (the License)
* see accompanying file LICENSE for details.
*
* This software is distributed WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the License for more information.
*/
#ifndef __COOP_CONFIG_H__
#define __COOP_CONFIG_H__
#ifdef COOP_CONFIG_FILE
/*
* User defined config file
*/
# include COOP_CONFIG_FILE
#else
/**
* Default thread stack size.
*/
# ifndef CONFIG_DEFAULT_STACK_SIZE
# define CONFIG_DEFAULT_STACK_SIZE 0x100U
# endif
/**
* Maximum number of threads supported by the library.
* Defined as threads pool size.
*/
# ifndef CONFIG_MAX_THREADS
# define CONFIG_MAX_THREADS 5
# endif
/**
* Boolean parameter to enable @ref coop_idle().
*/
# ifndef CONFIG_OPT_IDLE
# define CONFIG_OPT_IDLE 1
# endif
/**
* Boolean parameter to enable @ref coop_yield_after().
*/
# ifndef CONFIG_OPT_YIELD_AFTER
# define CONFIG_OPT_YIELD_AFTER 1
# endif
/**
* Boolean parameter to enable @ref coop_wait(), @ref coop_notify().
*/
# ifndef CONFIG_OPT_WAIT
# define CONFIG_OPT_WAIT 1
# endif
/**
* Boolean parameter to enable @ref coop_stack_wm().
*/
# ifndef CONFIG_OPT_STACK_WM
# define CONFIG_OPT_STACK_WM 0
# endif
/**
* If the library is used to create static number of threads at its startup
* and the threads are not intended to exit, this boolean parameter may be
* configured to reduce the library footprint and memory usage.
*
* @note The parameter reduces the library by the code required for thread's
* stack memory deallocation (stack unwinding), therefore must not be used
* for dynamically created threads.
*
* @note For use for resource-constrained platforms only, where the standard
* configuration may be problematic.
*/
# ifndef CONFIG_NOEXIT_STATIC_THREADS
# define CONFIG_NOEXIT_STATIC_THREADS 0
# endif
/**
* Boolean parameter to control logging debug messages.
*
* @note Usage of this option usually requires substantial increasing of the
* thread stack sizes due to additional logging overhead. This may limit
* usage of this parameter on resource-constrained platforms.
*/
# ifndef COOP_DEBUG
# define COOP_DEBUG 0
# endif
/**
* Alternative implementation of @ref coop_dbg_log_cb() callback used for
* logging debug messages.
*
* Debug messages are logged if the library is compiled with @c COOP_DEBUG
* macro-define. Default implementation of the @c coop_dbg_log_cb routine
* depends on the underlying platform. By configuring the boolean parameter
* it is possible to provide custom implementation for the logging routine.
*
* Use the following code snippet:
*
* @code
* #if COOP_DEBUG
* void coop_dbg_log_cb(const char *format, ...)
* {
* // custom implementation goes here
* }
* #endif
* @endcode
*/
# ifndef CONFIG_DBG_LOG_CB_ALT
# define CONFIG_DBG_LOG_CB_ALT 0
# endif
/**
* Alternative implementation of @ref coop_tick_cb() callback.
* Default implementation depends on the underlying platform.
*
* @note The boolean parameter is valid only if at least one of the following
* features is enabled: @ref CONFIG_OPT_YIELD_AFTER, @ref CONFIG_OPT_IDLE,
* @ref CONFIG_OPT_WAIT.
*/
# ifndef CONFIG_TICK_CB_ALT
# define CONFIG_TICK_CB_ALT 0
# endif
/**
* Alternative implementation of @ref coop_idle_cb() callback.
* Default implementation depends on the underlying platform.
*
* @note The boolean parameter is valid only if @ref CONFIG_OPT_IDLE feature
* is enabled.
*/
# ifndef CONFIG_IDLE_CB_ALT
# define CONFIG_IDLE_CB_ALT 0
# endif
#endif
/*
* If a boolean parameter is defined w/o value assigned, it is assumed as
* configured.
*/
#define __XEXT1(__prm) (1##__prm)
#define __EXT1(__prm) __XEXT1(__prm)
#ifdef CONFIG_OPT_IDLE
# if (__EXT1(CONFIG_OPT_IDLE) == 1)
# undef CONFIG_OPT_IDLE
# define CONFIG_OPT_IDLE 1
# endif
#endif
#ifdef CONFIG_OPT_YIELD_AFTER
# if (__EXT1(CONFIG_OPT_YIELD_AFTER) == 1)
# undef CONFIG_OPT_YIELD_AFTER
# define CONFIG_OPT_YIELD_AFTER 1
# endif
#endif
#ifdef CONFIG_OPT_WAIT
# if (__EXT1(CONFIG_OPT_WAIT) == 1)
# undef CONFIG_OPT_WAIT
# define CONFIG_OPT_WAIT 1
# endif
#endif
#ifdef CONFIG_OPT_STACK_WM
# if (__EXT1(CONFIG_OPT_STACK_WM) == 1)
# undef CONFIG_OPT_STACK_WM
# define CONFIG_OPT_STACK_WM 1
# endif
#endif
#ifdef CONFIG_NOEXIT_STATIC_THREADS
# if (__EXT1(CONFIG_NOEXIT_STATIC_THREADS) == 1)
# undef CONFIG_NOEXIT_STATIC_THREADS
# define CONFIG_NOEXIT_STATIC_THREADS 1
# endif
#endif
#ifdef COOP_DEBUG
# if (__EXT1(COOP_DEBUG) == 1)
# undef COOP_DEBUG
# define COOP_DEBUG 1
# endif
#endif
#ifdef CONFIG_DBG_LOG_CB_ALT
# if (__EXT1(CONFIG_DBG_LOG_CB_ALT) == 1)
# undef CONFIG_DBG_LOG_CB_ALT
# define CONFIG_DBG_LOG_CB_ALT 1
# endif
#endif
#ifdef CONFIG_TICK_CB_ALT
# if (__EXT1(CONFIG_TICK_CB_ALT) == 1)
# undef CONFIG_TICK_CB_ALT
# define CONFIG_TICK_CB_ALT 1
# endif
#endif
#ifdef CONFIG_IDLE_CB_ALT
# if (__EXT1(CONFIG_IDLE_CB_ALT) == 1)
# undef CONFIG_IDLE_CB_ALT
# define CONFIG_IDLE_CB_ALT 1
# endif
#endif
#undef __EXT1
#undef __XEXT1
#endif /* __COOP_CONFIG_H__ */