InitializeOnceHelper: use std::function instead of C function pointer

InitializeOnceHelper calls Loader::AddDeferredInitializer which takes a
std::function, so it's eventually converted to that anyways. This commit just
does this a bit earlier, and by saving the step of the intermediate C function
pointer, this would now also work for capturing lambdas (which there are none
of at the moment).
This commit is contained in:
Julian Brost 2022-12-12 11:25:54 +01:00
parent c019f8c04a
commit 61285adcae
2 changed files with 3 additions and 2 deletions

View File

@ -5,7 +5,7 @@
using namespace icinga;
bool icinga::InitializeOnceHelper(void (*func)(), int priority)
bool icinga::InitializeOnceHelper(const std::function<void()>& func, int priority)
{
Loader::AddDeferredInitializer(func, priority);
return true;

View File

@ -4,6 +4,7 @@
#define INITIALIZE_H
#include "base/i2-base.hpp"
#include <functional>
namespace icinga
{
@ -13,7 +14,7 @@ namespace icinga
#define I2_UNIQUE_NAME(prefix) I2_TOKENPASTE2(prefix, __COUNTER__)
bool InitializeOnceHelper(void (*func)(), int priority = 0);
bool InitializeOnceHelper(const std::function<void()>& func, int priority = 0);
#define INITIALIZE_ONCE(func) \
namespace { namespace I2_UNIQUE_NAME(io) { \