EM-ODP  3.7.0
Event Machine on ODP
em_hook_types.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 /**
32  * @file
33  * EM internal API hook types & definitions
34  *
35  */
36 
37 #ifndef EM_HOOK_TYPES_H_
38 #define EM_HOOK_TYPES_H_
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 /* Max number of API-callback hook arrays */
45 #define API_HOOKS_MAX_TBL_SIZE 255
46 
47 /* EM API hook function types */
48 #define ALLOC_HOOK 1
49 #define FREE_HOOK 2
50 #define SEND_HOOK 3
51 /* Dispatcher callback function types */
52 #define DISPATCH_CALLBACK_ENTER 4
53 #define DISPATCH_CALLBACK_EXIT 5
54 /* Idle hook function types */
55 #define TO_IDLE_HOOK 6
56 #define TO_ACTIVE_HOOK 7
57 #define WHILE_IDLE_HOOK 8
58 
59 typedef void (*void_hook_t)(void);
60 
61 typedef union {
62  em_api_hook_alloc_t alloc;
63  em_api_hook_free_t free;
64  em_api_hook_send_t send;
65  em_dispatch_enter_func_t disp_enter;
66  em_dispatch_exit_func_t disp_exit;
67  em_idle_hook_to_idle_t to_idle;
68  em_idle_hook_to_active_t to_active;
69  em_idle_hook_while_idle_t while_idle;
70  void_hook_t void_hook;
71 } hook_fn_t;
72 
73 /**
74  * Table for storing API-callback hook function pointers.
75  */
76 typedef struct {
77  /* Hook function table */
79  /* Pad size to a multiple of cache line size */
80  void *end[0] ENV_CACHE_LINE_ALIGNED;
81 } hook_tbl_t;
82 
83 COMPILE_TIME_ASSERT(sizeof(hook_tbl_t) == ENV_CACHE_LINE_SIZE,
84  HOOK_ALIGNMENT_ERROR);
85 
86 /**
87  * API-callback hook functions (table of tables)
88  */
89 typedef struct {
90  /** Storage for multiple hook function tables */
91  hook_tbl_t hook_tbl_storage[API_HOOKS_MAX_TBL_SIZE];
92  /** Callback table edit lock */
93  env_spinlock_t lock;
94  /** Index of the current active callback table */
95  int idx;
96  /* Pad size to a multiple of cache line size */
97  void *end[0] ENV_CACHE_LINE_ALIGNED;
99 
100 COMPILE_TIME_ASSERT(sizeof(hook_storage_t) % ENV_CACHE_LINE_SIZE == 0,
101  HOOK_STORAGE_ALIGNMENT_ERROR);
102 
103 COMPILE_TIME_ASSERT(sizeof(hook_storage_t) / ENV_CACHE_LINE_SIZE ==
104  API_HOOKS_MAX_TBL_SIZE + 1, HOOK_STORAGE_SIZE_ERROR);
105 
106 #ifdef __cplusplus
107 }
108 #endif
109 
110 #endif /* EM_HOOK_TYPES_H_ */
hook_storage_t::idx
int idx
Definition: em_hook_types.h:95
em_dispatch_exit_func_t
void(* em_dispatch_exit_func_t)(em_eo_t eo)
Definition: event_machine_dispatcher.h:548
ENV_CACHE_LINE_SIZE
#define ENV_CACHE_LINE_SIZE
Definition: environment.h:62
em_idle_hook_to_active_t
void(* em_idle_hook_to_active_t)(void)
Definition: event_machine_hooks.h:186
em_api_hook_send_t
void(* em_api_hook_send_t)(const em_event_t events[], int num, em_queue_t queue, em_event_group_t event_group)
Definition: event_machine_hooks.h:158
em_idle_hook_while_idle_t
void(* em_idle_hook_while_idle_t)(void)
Definition: event_machine_hooks.h:196
em_idle_hook_to_idle_t
void(* em_idle_hook_to_idle_t)(uint64_t to_idle_delay_ns)
Definition: event_machine_hooks.h:175
ENV_CACHE_LINE_ALIGNED
#define ENV_CACHE_LINE_ALIGNED
Definition: environment.h:76
em_api_hook_alloc_t
void(* em_api_hook_alloc_t)(const em_event_t events[], int num_act, int num_req, uint32_t size, em_event_type_t type, em_pool_t pool)
Definition: event_machine_hooks.h:113
hook_tbl_t
Definition: em_hook_types.h:76
hook_storage_t::lock
env_spinlock_t lock
Definition: em_hook_types.h:93
hook_fn_t
Definition: em_hook_types.h:61
em_dispatch_enter_func_t
void(* em_dispatch_enter_func_t)(em_eo_t eo, void **eo_ctx, em_event_t events[], int num, em_queue_t *queue, void **q_ctx)
Definition: event_machine_dispatcher.h:533
EM_CALLBACKS_MAX
#define EM_CALLBACKS_MAX
Definition: event_machine_config.h:234
em_api_hook_free_t
void(* em_api_hook_free_t)(const em_event_t events[], int num)
Definition: event_machine_hooks.h:138
hook_storage_t
Definition: em_hook_types.h:89