40 #ifndef included_vlib_init_h 41 #define included_vlib_init_h 53 typedef struct _vlib_init_function_list_elt
55 struct _vlib_init_function_list_elt *next_init_function;
57 } _vlib_init_function_list_elt_t;
82 #define VLIB_REMOVE_FROM_LINKED_LIST(first,p,next) \ 89 __typeof__ (p) current = first; \ 90 while (current->next) \ 92 if (current->next == p) \ 94 current->next = current->next->next; \ 97 current = current->next; \ 103 #define _VLIB_INIT_FUNCTION_SYMBOL(x, type) \ 104 _vlib_##type##_function_##x 106 #define VLIB_INIT_FUNCTION_SYMBOL(x) \ 107 _VLIB_INIT_FUNCTION_SYMBOL(x, init) 108 #define VLIB_MAIN_LOOP_ENTER_FUNCTION_SYMBOL(x) \ 109 _VLIB_INIT_FUNCTION_SYMBOL(x, main_loop_enter) 110 #define VLIB_MAIN_LOOP_EXIT_FUNCTION_SYMBOL(x) \ 111 _VLIB_INIT_FUNCTION_SYMBOL(x, main_loop_exit) 112 #define VLIB_CONFIG_FUNCTION_SYMBOL(x) \ 113 _VLIB_INIT_FUNCTION_SYMBOL(x, config) 118 #define VLIB_DECLARE_INIT_FUNCTION(x, tag) \ 119 vlib_init_function_t * _VLIB_INIT_FUNCTION_SYMBOL (x, tag) = x; \ 120 static void __vlib_add_##tag##_function_##x (void) \ 121 __attribute__((__constructor__)) ; \ 122 static void __vlib_add_##tag##_function_##x (void) \ 124 vlib_main_t * vm = vlib_get_main(); \ 125 static _vlib_init_function_list_elt_t _vlib_init_function; \ 126 _vlib_init_function.next_init_function \ 127 = vm->tag##_function_registrations; \ 128 vm->tag##_function_registrations = &_vlib_init_function; \ 129 _vlib_init_function.f = &x; \ 131 static void __vlib_rm_##tag##_function_##x (void) \ 132 __attribute__((__destructor__)) ; \ 133 static void __vlib_rm_##tag##_function_##x (void) \ 135 vlib_main_t * vm = vlib_get_main(); \ 136 _vlib_init_function_list_elt_t *next; \ 137 if (vm->tag##_function_registrations->f == &x) \ 139 vm->tag##_function_registrations = \ 140 vm->tag##_function_registrations->next_init_function; \ 143 next = vm->tag##_function_registrations; \ 144 while (next->next_init_function) \ 146 if (next->next_init_function->f == &x) \ 148 next->next_init_function = \ 149 next->next_init_function->next_init_function; \ 152 next = next->next_init_function; \ 156 #define VLIB_INIT_FUNCTION(x) VLIB_DECLARE_INIT_FUNCTION(x,init) 157 #define VLIB_WORKER_INIT_FUNCTION(x) VLIB_DECLARE_INIT_FUNCTION(x,worker_init) 159 #define VLIB_MAIN_LOOP_ENTER_FUNCTION(x) \ 160 VLIB_DECLARE_INIT_FUNCTION(x,main_loop_enter) 161 #define VLIB_MAIN_LOOP_EXIT_FUNCTION(x) \ 162 VLIB_DECLARE_INIT_FUNCTION(x,main_loop_exit) 164 #define VLIB_CONFIG_FUNCTION(x,n,...) \ 165 __VA_ARGS__ vlib_config_function_runtime_t \ 166 VLIB_CONFIG_FUNCTION_SYMBOL(x); \ 167 static void __vlib_add_config_function_##x (void) \ 168 __attribute__((__constructor__)) ; \ 169 static void __vlib_add_config_function_##x (void) \ 171 vlib_main_t * vm = vlib_get_main(); \ 172 VLIB_CONFIG_FUNCTION_SYMBOL(x).next_registration \ 173 = vm->config_function_registrations; \ 174 vm->config_function_registrations \ 175 = &VLIB_CONFIG_FUNCTION_SYMBOL(x); \ 177 static void __vlib_rm_config_function_##x (void) \ 178 __attribute__((__destructor__)) ; \ 179 static void __vlib_rm_config_function_##x (void) \ 181 vlib_main_t * vm = vlib_get_main(); \ 182 vlib_config_function_runtime_t *p = \ 183 & VLIB_CONFIG_FUNCTION_SYMBOL (x); \ 184 VLIB_REMOVE_FROM_LINKED_LIST \ 185 (vm->config_function_registrations, p, next_registration);\ 187 vlib_config_function_runtime_t \ 188 VLIB_CONFIG_FUNCTION_SYMBOL (x) \ 195 #define VLIB_EARLY_CONFIG_FUNCTION(x,n,...) \ 196 __VA_ARGS__ vlib_config_function_runtime_t \ 197 VLIB_CONFIG_FUNCTION_SYMBOL(x); \ 198 static void __vlib_add_config_function_##x (void) \ 199 __attribute__((__constructor__)) ; \ 200 static void __vlib_add_config_function_##x (void) \ 202 vlib_main_t * vm = vlib_get_main(); \ 203 VLIB_CONFIG_FUNCTION_SYMBOL(x).next_registration \ 204 = vm->config_function_registrations; \ 205 vm->config_function_registrations \ 206 = &VLIB_CONFIG_FUNCTION_SYMBOL(x); \ 208 static void __vlib_rm_config_function_##x (void) \ 209 __attribute__((__destructor__)) ; \ 210 static void __vlib_rm_config_function_##x (void) \ 212 vlib_main_t * vm = vlib_get_main(); \ 213 vlib_config_function_runtime_t *p = \ 214 & VLIB_CONFIG_FUNCTION_SYMBOL (x); \ 215 VLIB_REMOVE_FROM_LINKED_LIST \ 216 (vm->config_function_registrations, p, next_registration);\ 218 vlib_config_function_runtime_t \ 219 VLIB_CONFIG_FUNCTION_SYMBOL (x) \ 227 #define vlib_call_init_function(vm, x) \ 229 extern vlib_init_function_t * VLIB_INIT_FUNCTION_SYMBOL (x); \ 230 vlib_init_function_t * _f = VLIB_INIT_FUNCTION_SYMBOL (x); \ 231 clib_error_t * _error = 0; \ 232 if (! hash_get (vm->init_functions_called, _f)) \ 234 hash_set1 (vm->init_functions_called, _f); \ 241 #define vlib_mark_init_function_complete(vm, x) \ 243 extern vlib_init_function_t * VLIB_INIT_FUNCTION_SYMBOL (x); \ 244 vlib_init_function_t * _f = VLIB_INIT_FUNCTION_SYMBOL (x); \ 245 hash_set1 (vm->init_functions_called, _f); \ 248 #define vlib_call_post_graph_init_function(vm, x) \ 250 extern vlib_init_function_t * VLIB_POST_GRAPH_INIT_FUNCTION_SYMBOL (x); \ 251 vlib_init_function_t * _f = VLIB_POST_GRAPH_INIT_FUNCTION_SYMBOL (x); \ 252 clib_error_t * _error = 0; \ 253 if (! hash_get (vm->init_functions_called, _f)) \ 255 hash_set1 (vm->init_functions_called, _f); \ 261 #define vlib_call_config_function(vm, x) \ 263 vlib_config_function_runtime_t * _r; \ 264 clib_error_t * _error = 0; \ 265 extern vlib_config_function_runtime_t \ 266 VLIB_CONFIG_FUNCTION_SYMBOL (x); \ 268 _r = &VLIB_CONFIG_FUNCTION_SYMBOL (x); \ 269 if (! hash_get (vm->init_functions_called, _r->function)) \ 271 hash_set1 (vm->init_functions_called, _r->function); \ 272 _error = _r->function (vm, &_r->input); \ 286 _vlib_init_function_list_elt_t *
287 head,
int call_once);
289 #define foreach_vlib_module_reference \ 294 #define _(x) void vlib_##x##_reference (void); clib_error_t * vlib_call_all_main_loop_exit_functions(struct vlib_main_t *vm)
#define foreach_vlib_module_reference
clib_error_t * vlib_call_all_init_functions(struct vlib_main_t *vm)
clib_error_t *( vlib_config_function_t)(struct vlib_main_t *vm, unformat_input_t *input)
clib_error_t * vlib_call_init_exit_functions(struct vlib_main_t *vm, _vlib_init_function_list_elt_t *head, int call_once)
clib_error_t *( vlib_init_function_t)(struct vlib_main_t *vm)
struct vlib_config_function_runtime_t vlib_config_function_runtime_t
clib_error_t * vlib_call_all_config_functions(struct vlib_main_t *vm, unformat_input_t *input, int is_early)
clib_error_t * vlib_call_all_main_loop_enter_functions(struct vlib_main_t *vm)
struct vlib_config_function_runtime_t * next_registration