]> granicus.if.org Git - icinga2/blob - lib/base/initialize.hpp
Merge pull request #7185 from Icinga/bugfix/gelfwriter-wrong-log-facility
[icinga2] / lib / base / initialize.hpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #ifndef INITIALIZE_H
4 #define INITIALIZE_H
5
6 #include "base/i2-base.hpp"
7
8 namespace icinga
9 {
10
11 #define I2_TOKENPASTE(x, y) x ## y
12 #define I2_TOKENPASTE2(x, y) I2_TOKENPASTE(x, y)
13
14 #define I2_UNIQUE_NAME(prefix) I2_TOKENPASTE2(prefix, __COUNTER__)
15
16 bool InitializeOnceHelper(void (*func)(), int priority = 0);
17
18 #define INITIALIZE_ONCE(func)                                                                   \
19         namespace { namespace I2_UNIQUE_NAME(io) {                                                      \
20                 bool l_InitializeOnce(icinga::InitializeOnceHelper(func));              \
21         } }
22
23 #define INITIALIZE_ONCE_WITH_PRIORITY(func, priority)                                           \
24         namespace { namespace I2_UNIQUE_NAME(io) {                                                      \
25                 bool l_InitializeOnce(icinga::InitializeOnceHelper(func, priority));    \
26         } }
27 }
28
29 #endif /* INITIALIZE_H */