34 get_hook_tbl(
const uint8_t hook_type,
hook_storage_t **hook_storage );
43 pack_hook_tbl(
hook_tbl_t hook_tbl[],
unsigned int idx);
50 EM_PRINT(
"EM callbacks init\n");
62 em_shm->dispatch_enter_cb_tbl =
63 &
em_shm->dispatch_enter_cb_storage.hook_tbl_storage[0];
65 &
em_shm->dispatch_exit_cb_storage.hook_tbl_storage[0];
67 &
em_shm->alloc_hook_storage.hook_tbl_storage[0];
69 &
em_shm->free_hook_storage.hook_tbl_storage[0];
71 &
em_shm->send_hook_storage.hook_tbl_storage[0];
80 em_shm->dispatch_enter_cb_storage.idx = 0;
81 em_shm->dispatch_exit_cb_storage.idx = 0;
82 em_shm->alloc_hook_storage.idx = 0;
83 em_shm->free_hook_storage.idx = 0;
84 em_shm->send_hook_storage.idx = 0;
90 env_spinlock_init(&
em_shm->dispatch_enter_cb_storage.lock);
91 env_spinlock_init(&
em_shm->dispatch_exit_cb_storage.lock);
92 env_spinlock_init(&
em_shm->alloc_hook_storage.lock);
93 env_spinlock_init(&
em_shm->free_hook_storage.lock);
94 env_spinlock_init(&
em_shm->send_hook_storage.lock);
103 if (unlikely(stat !=
EM_OK))
108 if (unlikely(stat !=
EM_OK))
113 if (unlikely(stat !=
EM_OK))
121 if (unlikely(stat !=
EM_OK))
126 if (unlikely(stat !=
EM_OK))
131 if (unlikely(stat !=
EM_OK))
151 active_tbl_ptr = get_hook_tbl(hook_type, &hook_storage);
152 if (unlikely(active_tbl_ptr == NULL))
155 env_spinlock_lock(&hook_storage->
lock);
159 idx = hook_storage->
idx;
161 if (next_idx >= API_HOOKS_MAX_TBL_SIZE)
170 memcpy(next_tbl->tbl, hook_tbl->tbl,
sizeof(next_tbl->tbl));
173 if (next_tbl->tbl[i].void_hook == NULL)
177 env_spinlock_unlock(&hook_storage->
lock);
181 next_tbl->tbl[i] = hook_fn;
184 *active_tbl_ptr = next_tbl;
186 hook_storage->
idx = next_idx;
188 env_spinlock_unlock(&hook_storage->
lock);
205 active_tbl_ptr = get_hook_tbl(hook_type, &hook_storage);
206 if (unlikely(active_tbl_ptr == NULL))
209 env_spinlock_lock(&hook_storage->
lock);
213 idx = hook_storage->
idx;
215 if (next_idx >= API_HOOKS_MAX_TBL_SIZE)
224 memcpy(next_tbl->tbl, hook_tbl->tbl,
sizeof(next_tbl->tbl));
227 if (next_tbl->tbl[i].void_hook == hook_fn.void_hook)
230 env_spinlock_unlock(&hook_storage->
lock);
238 next_tbl->tbl[i].void_hook = NULL;
239 ret = pack_hook_tbl(next_tbl, i);
240 if (unlikely(ret != 0)) {
241 env_spinlock_unlock(&hook_storage->
lock);
246 *active_tbl_ptr = next_tbl;
248 hook_storage->
idx = next_idx;
250 env_spinlock_unlock(&hook_storage->
lock);
256 get_hook_tbl(
const uint8_t hook_type,
hook_storage_t **hook_storage )
262 *hook_storage = &
em_shm->alloc_hook_storage;
266 *hook_storage = &
em_shm->free_hook_storage;
270 *hook_storage = &
em_shm->send_hook_storage;
273 case DISPATCH_CALLBACK_ENTER:
274 *hook_storage = &
em_shm->dispatch_enter_cb_storage;
275 active_tbl_ptr = &
em_shm->dispatch_enter_cb_tbl;
277 case DISPATCH_CALLBACK_EXIT:
278 *hook_storage = &
em_shm->dispatch_exit_cb_storage;
289 case WHILE_IDLE_HOOK:
297 return active_tbl_ptr;
301 pack_hook_tbl(
hook_tbl_t *
const hook_tbl,
unsigned int idx)
306 fn_tbl[idx].void_hook != NULL))
310 if (fn_tbl[i + 1].void_hook != NULL) {
311 fn_tbl[i].void_hook = fn_tbl[i + 1].void_hook;
312 fn_tbl[i + 1].void_hook = NULL;
em_status_t hooks_init(const em_api_hooks_t *api_hooks, const em_idle_hooks_t *idle_hooks)
em_status_t hook_unregister(uint8_t type, hook_fn_t hook_fn)
em_status_t hook_register(uint8_t type, hook_fn_t hook_fn)
#define EM_IDLE_HOOKS_ENABLE
#define EM_API_HOOKS_ENABLE
em_status_t em_hooks_register_to_active(em_idle_hook_to_active_t func)
em_status_t em_hooks_register_alloc(em_api_hook_alloc_t func)
em_status_t em_hooks_register_free(em_api_hook_free_t func)
em_status_t em_hooks_register_to_idle(em_idle_hook_to_idle_t func)
em_status_t em_hooks_register_while_idle(em_idle_hook_while_idle_t func)
em_status_t em_hooks_register_send(em_api_hook_send_t func)
em_api_hook_send_t send_hook
em_api_hook_alloc_t alloc_hook
em_api_hook_free_t free_hook
em_idle_hook_to_idle_t to_idle_hook
em_idle_hook_to_active_t to_active_hook
em_idle_hook_while_idle_t while_idle_hook
hook_tbl_t * alloc_hook_tbl
hook_storage_t while_idle_hook_storage
hook_storage_t to_active_hook_storage
hook_tbl_t * to_idle_hook_tbl
hook_tbl_t * to_active_hook_tbl
hook_storage_t to_idle_hook_storage
hook_tbl_t * while_idle_hook_tbl
hook_tbl_t * free_hook_tbl
hook_tbl_t * dispatch_exit_cb_tbl
hook_tbl_t * send_hook_tbl
hook_tbl_t hook_tbl_storage[API_HOOKS_MAX_TBL_SIZE]