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;
61 } _vlib_init_function_list_elt_t;
86 #define VLIB_REMOVE_FROM_LINKED_LIST(first,p,next) \ 93 __typeof__ (p) current = first; \ 94 while (current->next) \ 96 if (current->next == p) \ 98 current->next = current->next->next; \ 101 current = current->next; \ 107 #define _VLIB_INIT_FUNCTION_SYMBOL(x, type) \ 108 _vlib_##type##_function_##x 110 #define VLIB_INIT_FUNCTION_SYMBOL(x) \ 111 _VLIB_INIT_FUNCTION_SYMBOL(x, init) 112 #define VLIB_MAIN_LOOP_ENTER_FUNCTION_SYMBOL(x) \ 113 _VLIB_INIT_FUNCTION_SYMBOL(x, main_loop_enter) 114 #define VLIB_MAIN_LOOP_EXIT_FUNCTION_SYMBOL(x) \ 115 _VLIB_INIT_FUNCTION_SYMBOL(x, main_loop_exit) 116 #define VLIB_CONFIG_FUNCTION_SYMBOL(x) \ 117 _VLIB_INIT_FUNCTION_SYMBOL(x, config) 122 #ifndef CLIB_MARCH_VARIANT 123 #define VLIB_DECLARE_INIT_FUNCTION(x, tag) \ 124 vlib_init_function_t * _VLIB_INIT_FUNCTION_SYMBOL (x, tag) = x; \ 125 static void __vlib_add_##tag##_function_##x (void) \ 126 __attribute__((__constructor__)) ; \ 127 static _vlib_init_function_list_elt_t _vlib_init_function_##tag_##x; \ 128 static void __vlib_add_##tag##_function_##x (void) \ 130 vlib_main_t * vm = vlib_get_main(); \ 131 _vlib_init_function_##tag_##x.next_init_function \ 132 = vm->tag##_function_registrations; \ 133 vm->tag##_function_registrations = &_vlib_init_function_##tag_##x; \ 134 _vlib_init_function_##tag_##x.f = &x; \ 135 _vlib_init_function_##tag_##x.name = #x; \ 137 static void __vlib_rm_##tag##_function_##x (void) \ 138 __attribute__((__destructor__)) ; \ 139 static void __vlib_rm_##tag##_function_##x (void) \ 141 vlib_main_t * vm = vlib_get_main(); \ 142 _vlib_init_function_list_elt_t *this, *prev; \ 143 this = vm->tag##_function_registrations; \ 148 vm->tag##_function_registrations = this->next_init_function; \ 152 this = this->next_init_function; \ 157 prev->next_init_function = \ 158 this->next_init_function; \ 162 this = this->next_init_function; \ 165 static _vlib_init_function_list_elt_t _vlib_init_function_##tag_##x 169 #define VLIB_DECLARE_INIT_FUNCTION(x, tag) \ 170 static __clib_unused void * __clib_unused_##tag##_##x = x 173 #define VLIB_INIT_FUNCTION(x) VLIB_DECLARE_INIT_FUNCTION(x,init) 174 #define VLIB_WORKER_INIT_FUNCTION(x) VLIB_DECLARE_INIT_FUNCTION(x,worker_init) 176 #define VLIB_MAIN_LOOP_ENTER_FUNCTION(x) \ 177 VLIB_DECLARE_INIT_FUNCTION(x,main_loop_enter) 178 #define VLIB_MAIN_LOOP_EXIT_FUNCTION(x) \ 179 VLIB_DECLARE_INIT_FUNCTION(x,main_loop_exit) 181 #ifndef CLIB_MARCH_VARIANT 182 #define VLIB_CONFIG_FUNCTION(x,n,...) \ 183 __VA_ARGS__ vlib_config_function_runtime_t \ 184 VLIB_CONFIG_FUNCTION_SYMBOL(x); \ 185 static void __vlib_add_config_function_##x (void) \ 186 __attribute__((__constructor__)) ; \ 187 static void __vlib_add_config_function_##x (void) \ 189 vlib_main_t * vm = vlib_get_main(); \ 190 VLIB_CONFIG_FUNCTION_SYMBOL(x).next_registration \ 191 = vm->config_function_registrations; \ 192 vm->config_function_registrations \ 193 = &VLIB_CONFIG_FUNCTION_SYMBOL(x); \ 195 static void __vlib_rm_config_function_##x (void) \ 196 __attribute__((__destructor__)) ; \ 197 static void __vlib_rm_config_function_##x (void) \ 199 vlib_main_t * vm = vlib_get_main(); \ 200 vlib_config_function_runtime_t *p = \ 201 & VLIB_CONFIG_FUNCTION_SYMBOL (x); \ 202 VLIB_REMOVE_FROM_LINKED_LIST \ 203 (vm->config_function_registrations, p, next_registration);\ 205 vlib_config_function_runtime_t \ 206 VLIB_CONFIG_FUNCTION_SYMBOL (x) \ 215 #define VLIB_CONFIG_FUNCTION(x,n,...) \ 216 static __clib_unused vlib_config_function_runtime_t \ 217 VLIB_CONFIG_FUNCTION_SYMBOL (__clib_unused_##x) \ 225 #ifndef CLIB_MARCH_VARIANT 226 #define VLIB_EARLY_CONFIG_FUNCTION(x,n,...) \ 227 __VA_ARGS__ vlib_config_function_runtime_t \ 228 VLIB_CONFIG_FUNCTION_SYMBOL(x); \ 229 static void __vlib_add_config_function_##x (void) \ 230 __attribute__((__constructor__)) ; \ 231 static void __vlib_add_config_function_##x (void) \ 233 vlib_main_t * vm = vlib_get_main(); \ 234 VLIB_CONFIG_FUNCTION_SYMBOL(x).next_registration \ 235 = vm->config_function_registrations; \ 236 vm->config_function_registrations \ 237 = &VLIB_CONFIG_FUNCTION_SYMBOL(x); \ 239 static void __vlib_rm_config_function_##x (void) \ 240 __attribute__((__destructor__)) ; \ 241 static void __vlib_rm_config_function_##x (void) \ 243 vlib_main_t * vm = vlib_get_main(); \ 244 vlib_config_function_runtime_t *p = \ 245 & VLIB_CONFIG_FUNCTION_SYMBOL (x); \ 246 VLIB_REMOVE_FROM_LINKED_LIST \ 247 (vm->config_function_registrations, p, next_registration);\ 249 vlib_config_function_runtime_t \ 250 VLIB_CONFIG_FUNCTION_SYMBOL (x) \ 259 #define VLIB_EARLY_CONFIG_FUNCTION(x,n,...) \ 260 static __clib_unused vlib_config_function_runtime_t \ 261 VLIB_CONFIG_FUNCTION_SYMBOL (__clib_unused_##x) \ 270 #define vlib_call_init_function(vm, x) \ 272 extern vlib_init_function_t * VLIB_INIT_FUNCTION_SYMBOL (x); \ 273 vlib_init_function_t * _f = VLIB_INIT_FUNCTION_SYMBOL (x); \ 274 clib_error_t * _error = 0; \ 275 if (! hash_get (vm->init_functions_called, _f)) \ 277 hash_set1 (vm->init_functions_called, _f); \ 284 #define vlib_mark_init_function_complete(vm, x) \ 286 extern vlib_init_function_t * VLIB_INIT_FUNCTION_SYMBOL (x); \ 287 vlib_init_function_t * _f = VLIB_INIT_FUNCTION_SYMBOL (x); \ 288 hash_set1 (vm->init_functions_called, _f); \ 291 #define vlib_call_post_graph_init_function(vm, x) \ 293 extern vlib_init_function_t * VLIB_POST_GRAPH_INIT_FUNCTION_SYMBOL (x); \ 294 vlib_init_function_t * _f = VLIB_POST_GRAPH_INIT_FUNCTION_SYMBOL (x); \ 295 clib_error_t * _error = 0; \ 296 if (! hash_get (vm->init_functions_called, _f)) \ 298 hash_set1 (vm->init_functions_called, _f); \ 304 #define vlib_call_config_function(vm, x) \ 306 vlib_config_function_runtime_t * _r; \ 307 clib_error_t * _error = 0; \ 308 extern vlib_config_function_runtime_t \ 309 VLIB_CONFIG_FUNCTION_SYMBOL (x); \ 311 _r = &VLIB_CONFIG_FUNCTION_SYMBOL (x); \ 312 if (! hash_get (vm->init_functions_called, _r->function)) \ 314 hash_set1 (vm->init_functions_called, _r->function); \ 315 _error = _r->function (vm, &_r->input); \ 320 #define vlib_call_main_loop_enter_function(vm, x) \ 322 extern vlib_init_function_t * VLIB_MAIN_LOOP_ENTER_FUNCTION_SYMBOL (x); \ 323 vlib_init_function_t * _f = VLIB_MAIN_LOOP_ENTER_FUNCTION_SYMBOL (x); \ 324 clib_error_t * _error = 0; \ 325 if (! hash_get (vm->init_functions_called, _f)) \ 327 hash_set1 (vm->init_functions_called, _f); \ 342 _vlib_init_function_list_elt_t **
343 headp,
int call_once);
345 _vlib_init_function_list_elt_t
346 ** headp,
int call_once);
349 #define foreach_vlib_module_reference \ 354 #define _(x) void vlib_##x##_reference (void); 357 #define VLIB_INITS(...) (char*[]) { __VA_ARGS__, 0} 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_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)
clib_error_t * vlib_sort_init_exit_functions(_vlib_init_function_list_elt_t **)
Topological sorter for init function chains.
clib_error_t *() vlib_config_function_t(struct vlib_main_t *vm, unformat_input_t *input)
struct vlib_config_function_runtime_t * next_registration
clib_error_t * vlib_call_init_exit_functions(struct vlib_main_t *vm, _vlib_init_function_list_elt_t **headp, int call_once)
clib_error_t * vlib_call_init_exit_functions_no_sort(struct vlib_main_t *vm, _vlib_init_function_list_elt_t **headp, int call_once)