EM-ODP 4.4.0
Event Machine on ODP
Loading...
Searching...
No Matches
em_event_state.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020, Nokia Solutions and Networks
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * * Neither the name of the copyright holder nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 /**
32 * @file
33 * EM event state verification support
34 */
35
36#ifndef EM_EVENT_CHECKS_H_
37#define EM_EVENT_CHECKS_H_
38
39#include <stdbool.h>
40#include <stdint.h>
41
42#include <event_machine.h>
43
44#include "em_event_types.h"
45#include "em_mem.h"
46
47#ifdef __cplusplus
48extern "C" {
49#endif
50
51/**
52 * @brief ESV API operation IDs
53 */
54typedef enum {
55 EVSTATE__UNDEF = 0, /* Must be first! */
56 EVSTATE__PREALLOC,
57 EVSTATE__ALLOC,
58 EVSTATE__ALLOC_MULTI,
59 EVSTATE__EVENT_CLONE,
60 EVSTATE__EVENT_REF,
61 EVSTATE__FREE,
62 EVSTATE__FREE_MULTI,
63 EVSTATE__EVENT_VECTOR_FREE,
64 EVSTATE__INIT,
65 EVSTATE__INIT_MULTI,
66 EVSTATE__INIT_EXTEV,
67 EVSTATE__INIT_EXTEV_MULTI,
68 EVSTATE__UPDATE_EXTEV,
69 EVSTATE__SEND,
70 EVSTATE__SEND__FAIL,
71 EVSTATE__SEND_EGRP,
72 EVSTATE__SEND_EGRP__FAIL,
73 EVSTATE__SEND_MULTI,
74 EVSTATE__SEND_MULTI__FAIL,
75 EVSTATE__SEND_EGRP_MULTI,
76 EVSTATE__SEND_EGRP_MULTI__FAIL,
77 EVSTATE__EO_START_SEND_BUFFERED,
78 EVSTATE__MARK_SEND,
79 EVSTATE__UNMARK_SEND,
80 EVSTATE__MARK_FREE,
81 EVSTATE__UNMARK_FREE,
82 EVSTATE__MARK_FREE_MULTI,
83 EVSTATE__UNMARK_FREE_MULTI,
84 EVSTATE__DISPATCH,
85 EVSTATE__DISPATCH_MULTI,
86 EVSTATE__DISPATCH_AGGR, /* inner event of aggregation-produced vector */
87 EVSTATE__DISPATCH_SCHED__FAIL,
88 EVSTATE__DISPATCH_LOCAL__FAIL,
89 EVSTATE__DEQUEUE,
90 EVSTATE__DEQUEUE_MULTI,
91 EVSTATE__TMO_SET_ABS,
92 EVSTATE__TMO_SET_ABS__FAIL,
93 EVSTATE__TMO_SET_REL,
94 EVSTATE__TMO_SET_REL__FAIL,
95 EVSTATE__TMO_SET_PERIODIC,
96 EVSTATE__TMO_SET_PERIODIC__FAIL,
97 EVSTATE__TMO_CANCEL,
98 EVSTATE__TMO_ACK,
99 EVSTATE__TMO_ACK__NOSKIP,
100 EVSTATE__TMO_ACK__FAIL,
101 EVSTATE__TMO_CREATE,
102 EVSTATE__TMO_DELETE,
103 EVSTATE__AG_DELETE,
104 EVSTATE__TERM_CORE__QUEUE_LOCAL,
105 EVSTATE__TERM,
106 EVSTATE__LAST /* Must be last! */
108
109/* esv_apiop_t::EVSTATE__LAST must fit into ev_hdr_state_t::uint8_t api_op */
110COMPILE_TIME_ASSERT(EVSTATE__LAST <= UINT8_MAX, EVSTATE__LAST__TOO_BIG);
111
112/**
113 * Init values for the event-state counters.
114 *
115 * The counters are 16-bit but are updated as one combined 64-bit atomic var,
116 * thus the init values are in the middle of the u16-range to avoid wraparounds
117 * when decrementing below '0'.
118 */
119/** Initial event generation value */
120#define EVGEN_INIT ((uint16_t)0x1000)
121/** Max evgen value before resetting to 'EVGEN_INIT' to avoid wrap */
122#define EVGEN_MAX ((uint16_t)UINT16_MAX - 0x1000)
123/** Initial send count value */
124#define SEND_CNT_INIT ((uint16_t)0x8000) /* = 0 + 'offset' */
125/** Initial reference count value */
126#define REF_CNT_INIT ((uint16_t)0x8000) /* = 0 + 'offset' */
127
128/**
129 * Return 'true' if ESV is enabled
130 *
131 * - EM_ESV_ENABLE is set via the 'configure' script: --enable/disable-esv
132 * - esv.enable' is set via the EM config file (default: conf/em-odp.conf)
133 */
134static inline bool esv_enabled(void)
135{
136 return EM_ESV_ENABLE && em_shm->opt.esv.enable;
137}
138
139/**
140 * Init ESV (if enabled at compile time), read config options
141 */
143/**
144 * Set the initial event state during em_pool_create() when preallocating events
145 */
146em_event_t evstate_prealloc(const em_event_t event, event_hdr_t *const ev_hdr);
147/**
148 * Set the initial event state during timeout allocation.
149 */
150em_event_t evstate_alloc_tmo(const em_event_t event, event_hdr_t *const ev_hdr);
151/**
152 * Set the initial event state during em_alloc() / em_event_clone()
153 */
154em_event_t evstate_alloc(const em_event_t event, event_hdr_t *const ev_hdr,
155 const uint16_t api_op);
156/**
157 * Set the initial state of multiple events during em_alloc_multi()
158 */
159void evstate_alloc_multi(em_event_t ev_tbl[/*in/out*/],
160 event_hdr_t *const ev_hdr_tbl[], const int num);
161/**
162 * Update event state during em_event_ref()
163 */
164em_event_t evstate_ref(const em_event_t event, event_hdr_t *const ev_hdr);
165
166/**
167 * Set the initial state for an event
168 * (e.g. an new odp-event converted into an EM-event)
169 */
170em_event_t evstate_init(const em_event_t event, event_hdr_t *const ev_hdr,
171 bool is_extev);
172/**
173 * Set the initial state for events
174 * (e.g. new odp-events converted into EM-events)
175 */
176void evstate_init_multi(em_event_t ev_tbl[/*in/out*/],
177 event_hdr_t *const ev_hdr_tbl[], const int num,
178 bool is_extev);
179
180/**
181 * Update the state for external events input into EM.
182 * Used when esv.prealloc_pools = true and the input event was allocated
183 * externally to EM (e.g. by ODP) but from an EM event-pool.
184 */
185em_event_t evstate_update(const em_event_t event,
186 event_hdr_t *const ev_hdr, bool is_extev);
187
188/**
189 * Check & update event state during em_free() or em_event_mark_free()
190 */
191void evstate_free(const em_event_t event, event_hdr_t *const ev_hdr,
192 const uint16_t api_op);
193/**
194 * Check & update event state during em_event_unmark_free()
195 */
196void evstate_free_revert(const em_event_t event, event_hdr_t *const ev_hdr,
197 const uint16_t api_op);
198
199/**
200 * Check & update the state of multiple events during em_free_multi() or
201 * em_event_mark_free_multi()
202 */
203void evstate_free_multi(const em_event_t ev_tbl[],
204 event_hdr_t *const ev_hdr_tbl[], const int num,
205 const uint16_t api_op);
206/**
207 * Check & update event state during em_event_unmark_free_multi()
208 */
209void evstate_free_revert_multi(const em_event_t ev_tbl[],
210 event_hdr_t *const ev_hdr_tbl[], const int num,
211 const uint16_t api_op);
212/**
213 * Check & update event state - event passed from EM to user.
214 *
215 * em_dispatch(), em_queue_dequeue(), em_tmo_cancel(), em_tmo_delete()
216 */
217em_event_t evstate_em2usr(const em_event_t event, event_hdr_t *const ev_hdr,
218 const uint16_t api_op);
219/**
220 * Revert EM-to-user event-state update on failed operation.
221 */
222em_event_t evstate_em2usr_revert(const em_event_t event, event_hdr_t *const ev_hdr,
223 const uint16_t api_op);
224/**
225 * Check & update the state of multiple events - events passed from EM to user
226 *
227 * em_dispatch(), em_queue_dequeue_multi(), em_term()
228 */
229void evstate_em2usr_multi(em_event_t ev_tbl[/*in/out*/],
230 event_hdr_t *const ev_hdr_tbl[], const int num,
231 const uint16_t api_op);
232/**
233 * Revert EM-to-user event-state updates on failed operation.
234 */
235void evstate_em2usr_revert_multi(em_event_t ev_tbl[/*in/out*/],
236 event_hdr_t *const ev_hdr_tbl[], const int num,
237 const uint16_t api_op);
238/**
239 * Check & update event state - event passed from the user to EM.
240 *
241 * em_send(), em_send_group(), em_tmo_set_abs/rel/periodic(), em_tmo_ack()
242 */
243void evstate_usr2em(const em_event_t event, event_hdr_t *const ev_hdr,
244 const uint16_t api_op);
245/**
246 * Revert user-to-EM event-state update on failed operation.
247 */
248void evstate_usr2em_revert(const em_event_t event, event_hdr_t *const ev_hdr,
249 const uint16_t api_op);
250/**
251 * Check & update the state of multiple events - events passed from user to EM
252 *
253 * em_send_multi(), em_send_group_multi()
254 */
255void evstate_usr2em_multi(const em_event_t ev_tbl[],
256 event_hdr_t *const ev_hdr_tbl[], const int num,
257 const uint16_t api_op);
258/**
259 * Revert user-to-EM event-state updates on failed operation.
260 */
261void evstate_usr2em_revert_multi(const em_event_t ev_tbl[],
262 event_hdr_t *const ev_hdr_tbl[], const int num,
263 const uint16_t api_op);
264/**
265 * Check & update event state during em_event_unmark_send()
266 *
267 * Wrapper function for evstate_usr2em_revert(..., EVSTATE__UNMARK_SEND) with
268 * extra error checks.
269 */
270void evstate_unmark_send(const em_event_t event, event_hdr_t *const ev_hdr);
271
272/**
273 * Check & update event state during em_event_unmark_free()
274 *
275 * Wrapper function for evstate_free_revert(..., EVSTATE__UNMARK_FREE) with
276 * extra error checks.
277 */
278void evstate_unmark_free(const em_event_t event, event_hdr_t *const ev_hdr,
279 const uint16_t api_op);
280
281/**
282 * Check & update event state for multiple events during
283 * em_event_unmark_free_multi()
284 *
285 * Wrapper function for
286 * evstate_free_revert_multi(..., EVSTATE__UNMARK_FREE_MULTI)
287 * with extra error checks.
288 */
289void evstate_unmark_free_multi(const em_event_t ev_tbl[],
290 event_hdr_t *const ev_hdr_tbl[], const int num,
291 const uint16_t api_op);
292
293#ifdef __cplusplus
294}
295#endif
296
297#endif /* EM_EVENT_CHECKS_H_ */
em_event_t evstate_em2usr(const em_event_t event, event_hdr_t *const ev_hdr, const uint16_t api_op)
em_event_t evstate_init(const em_event_t event, event_hdr_t *const ev_hdr, bool is_extev)
void evstate_em2usr_revert_multi(em_event_t ev_tbl[], event_hdr_t *const ev_hdr_tbl[], const int num, const uint16_t api_op)
void evstate_alloc_multi(em_event_t ev_tbl[], event_hdr_t *const ev_hdr_tbl[], const int num)
void evstate_free_multi(const em_event_t ev_tbl[], event_hdr_t *const ev_hdr_tbl[], const int num, const uint16_t api_op)
em_event_t evstate_ref(const em_event_t event, event_hdr_t *const ev_hdr)
em_event_t evstate_alloc_tmo(const em_event_t event, event_hdr_t *const ev_hdr)
void evstate_usr2em_revert(const em_event_t event, event_hdr_t *const ev_hdr, const uint16_t api_op)
void evstate_usr2em(const em_event_t event, event_hdr_t *const ev_hdr, const uint16_t api_op)
em_event_t evstate_alloc(const em_event_t event, event_hdr_t *const ev_hdr, const uint16_t api_op)
void evstate_free(const em_event_t event, event_hdr_t *const ev_hdr, const uint16_t api_op)
void evstate_init_multi(em_event_t ev_tbl[], event_hdr_t *const ev_hdr_tbl[], const int num, bool is_extev)
void evstate_usr2em_revert_multi(const em_event_t ev_tbl[], event_hdr_t *const ev_hdr_tbl[], const int num, const uint16_t api_op)
void evstate_usr2em_multi(const em_event_t ev_tbl[], event_hdr_t *const ev_hdr_tbl[], const int num, const uint16_t api_op)
void evstate_free_revert_multi(const em_event_t ev_tbl[], event_hdr_t *const ev_hdr_tbl[], const int num, const uint16_t api_op)
void evstate_unmark_send(const em_event_t event, event_hdr_t *const ev_hdr)
esv_apiop_t
ESV API operation IDs.
void evstate_em2usr_multi(em_event_t ev_tbl[], event_hdr_t *const ev_hdr_tbl[], const int num, const uint16_t api_op)
void evstate_unmark_free(const em_event_t event, event_hdr_t *const ev_hdr, const uint16_t api_op)
em_event_t evstate_prealloc(const em_event_t event, event_hdr_t *const ev_hdr)
void evstate_free_revert(const em_event_t event, event_hdr_t *const ev_hdr, const uint16_t api_op)
em_event_t evstate_em2usr_revert(const em_event_t event, event_hdr_t *const ev_hdr, const uint16_t api_op)
em_event_t evstate_update(const em_event_t event, event_hdr_t *const ev_hdr, bool is_extev)
void evstate_unmark_free_multi(const em_event_t ev_tbl[], event_hdr_t *const ev_hdr_tbl[], const int num, const uint16_t api_op)
em_status_t esv_init(void)
em_shm_t * em_shm
#define EM_ESV_ENABLE
uint32_t em_status_t
em_cfgfile_opts_t opt
Definition em_mem.h:99