EM-ODP  3.7.0
Event Machine on ODP
em_eo.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015, 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 #ifndef EM_EO_H_
32 #define EM_EO_H_
33 
34 /**
35  * @file
36  * EM internal EO functions
37  *
38  */
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 #define invalid_eo(eo) ((unsigned int)eo_hdl2idx((eo)) >= EM_MAX_EOS)
45 
47 eo_init(eo_tbl_t eo_tbl[], eo_pool_t *eo_pool);
48 
49 em_eo_t
50 eo_alloc(void);
51 
53 eo_free(em_eo_t eo);
54 
56 eo_add_queue(eo_elem_t *const eo_elem, queue_elem_t *const q_elem);
57 
59 eo_rem_queue(eo_elem_t *const eo_elem, queue_elem_t *const q_elem);
60 
62 eo_rem_queue_all(eo_elem_t *const eo_elem);
63 
65 eo_delete_queue_all(eo_elem_t *const eo_elem);
66 
68 eo_start_local_req(eo_elem_t *const eo_elem,
69  int num_notif, const em_notif_t notif_tbl[]);
71 eo_start_sync_local_req(eo_elem_t *const eo_elem);
72 
73 int eo_start_buffer_events(const em_event_t events[], int num, em_queue_t queue);
74 
75 void eo_start_send_buffered_events(eo_elem_t *const eo_elem);
76 
78 eo_stop_local_req(eo_elem_t *const eo_elem,
79  int num_notif, const em_notif_t notif_tbl[]);
81 eo_stop_sync_local_req(eo_elem_t *const eo_elem);
82 
84 eo_remove_queue_local_req(eo_elem_t *const eo_elem, queue_elem_t *const q_elem,
85  int num_notif, const em_notif_t notif_tbl[]);
87 eo_remove_queue_sync_local_req(eo_elem_t *const eo_elem,
88  queue_elem_t *const q_elem);
90 eo_remove_queue_all_local_req(eo_elem_t *const eo_elem, int delete_queues,
91  int num_notif, const em_notif_t notif_tbl[]);
93 eo_remove_queue_all_sync_local_req(eo_elem_t *const eo_elem, int delete_queues);
94 
95 unsigned int
96 eo_count(void);
97 
98 size_t eo_get_name(const eo_elem_t *const eo_elem,
99  char name[/*out*/], const size_t maxlen);
100 
101 odp_stash_t eo_start_stash_create(void);
102 
103 static inline int
104 eo_allocated(const eo_elem_t *const eo_elem)
105 {
106  return !objpool_in_pool(&eo_elem->eo_pool_elem);
107 }
108 
109 /** Convert eo handle to eo index */
110 static inline int
111 eo_hdl2idx(em_eo_t eo)
112 {
113  return (int)(uintptr_t)eo - 1;
114 }
115 
116 /** Convert eo index to eo handle */
117 static inline em_eo_t
118 eo_idx2hdl(int eo_idx)
119 {
120  return (em_eo_t)(uintptr_t)(eo_idx + 1);
121 }
122 
123 /** Returns EO element associated with EO handle */
124 static inline eo_elem_t *
125 eo_elem_get(em_eo_t eo)
126 {
127  const int eo_idx = eo_hdl2idx(eo);
128  eo_elem_t *eo_elem;
129 
130  if (unlikely((unsigned int)eo_idx > EM_MAX_EOS - 1))
131  return NULL;
132 
133  eo_elem = &em_shm->eo_tbl.eo_elem[eo_idx];
134 
135  return eo_elem;
136 }
137 
138 /** Returns the EO element of the currently active EO (if any)*/
139 static inline eo_elem_t *
140 eo_elem_current(void)
141 {
142  const queue_elem_t *const q_elem = em_locm.current.q_elem;
143 
144  if (unlikely(q_elem == NULL))
145  return NULL;
146 
147  return q_elem->eo_elem;
148 }
149 
150 static inline em_eo_t
151 eo_current(void)
152 {
153  const queue_elem_t *const q_elem = em_locm.current.q_elem;
154 
155  if (unlikely(q_elem == NULL))
156  return EM_EO_UNDEF;
157 
158  return (em_eo_t)(uintptr_t)q_elem->eo;
159 }
160 
161 /**
162  * EM internal event handler (see em_internal_event.c&h)
163  * Handle the internal event requesting a local function call.
164  */
165 void
167 
168 /** Print information about all EOs */
169 void eo_info_print_all(void);
170 
171 /** Print information about all queues of the given eo */
172 void eo_queue_info_print(em_eo_t eo);
173 
174 #ifdef __cplusplus
175 }
176 #endif
177 
178 #endif /* EM_EO_H_ */
eo_pool_t
Definition: em_eo_types.h:94
eo_elem_t::eo_pool_elem
objpool_elem_t eo_pool_elem
Definition: em_eo_types.h:83
eo_info_print_all
void eo_info_print_all(void)
Definition: em_eo.c:1253
queue_elem_t::eo_elem
eo_elem_t * eo_elem
Definition: em_queue_types.h:249
em_locm
ENV_LOCAL em_locm_t em_locm
eo_queue_info_print
void eo_queue_info_print(em_eo_t eo)
Definition: em_eo.c:1326
em_locm_t::current
em_locm_current_t current
Definition: em_mem.h:190
EM_MAX_EOS
#define EM_MAX_EOS
Definition: event_machine_config.h:149
EM_EO_UNDEF
#define EM_EO_UNDEF
Definition: event_machine_types.h:95
eo_add_queue
em_status_t eo_add_queue(eo_elem_t *const eo_elem, queue_elem_t *const q_elem)
Definition: em_eo.c:164
eo_start_buffer_events
int eo_start_buffer_events(const em_event_t events[], int num, em_queue_t queue)
Definition: em_eo.c:412
eo_rem_queue
em_status_t eo_rem_queue(eo_elem_t *const eo_elem, queue_elem_t *const q_elem)
Definition: em_eo.c:221
eo_elem_t
Definition: em_eo_types.h:47
eo_start_stash_create
odp_stash_t eo_start_stash_create(void)
Create a stash used to buffer events sent during EO-start.
Definition: em_eo.c:1398
i_event__eo_local_func_call_req
void i_event__eo_local_func_call_req(const internal_event_t *i_ev)
Definition: em_eo.c:1073
internal_event_t
Definition: em_internal_event_types.h:93
em_status_t
uint32_t em_status_t
Definition: event_machine_types.h:321
ODP_PACKED::q_elem
queue_elem_t * q_elem
Definition: em_mem.h:174
em_shm
em_shm_t * em_shm
Definition: event_machine_init.c:41
queue_elem_t::eo
uint16_t eo
Definition: em_queue_types.h:222
em_notif_t
Definition: event_machine_types.h:268
eo_start_send_buffered_events
void eo_start_send_buffered_events(eo_elem_t *const eo_elem)
Definition: em_eo.c:471
eo_tbl_t
Definition: em_eo_types.h:89
queue_elem_t
Definition: em_queue_types.h:180