1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016, Olivier MATZ <zer0@droids-corp.org>
6 * Register initialization routines.
12 #include <sys/queue.h>
14 #include <ecoli_log.h>
15 #include <ecoli_node.h>
18 * Register initialization and exit callbacks. These callbacks are
19 * ordered by priority: for initialization, the lowest priority is called
20 * first. For exit, the callbacks are invoked in reverse order.
22 #define EC_INIT_REGISTER(t) \
23 static void ec_init_init_##t(void); \
24 static void __attribute__((constructor, used)) \
25 ec_init_init_##t(void) \
27 ec_init_register(&t); \
31 * Type of init function. Return 0 on success, -1 on error.
33 typedef int (ec_init_t)(void);
36 * Type of exit function.
38 typedef void (ec_exit_t)(void);
40 TAILQ_HEAD(ec_init_list, ec_init);
43 * A structure describing a test case.
46 TAILQ_ENTRY(ec_init) next; /**< Next in list. */
47 ec_init_t *init; /**< Init function. */
48 ec_exit_t *exit; /**< Exit function. */
49 unsigned int priority; /**< Priority (0=first, 99=last) */
53 * Register an initialization function.
56 * A pointer to a ec_init structure to be registered.
58 void ec_init_register(struct ec_init *test);
61 * Initialize ecoli library.
63 * Must be called before any other function from libecoli, except
64 * ec_malloc_register().
67 * 0 on success, -1 on error (errno is set).
72 * Uninitialize ecoli library.