From 61285adcae63f1bc295b1631f714df41d8452015 Mon Sep 17 00:00:00 2001 From: Julian Brost Date: Mon, 12 Dec 2022 11:25:54 +0100 Subject: [PATCH] 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). --- lib/base/initialize.cpp | 2 +- lib/base/initialize.hpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/base/initialize.cpp b/lib/base/initialize.cpp index 23373cc23..e1dbec547 100644 --- a/lib/base/initialize.cpp +++ b/lib/base/initialize.cpp @@ -5,7 +5,7 @@ using namespace icinga; -bool icinga::InitializeOnceHelper(void (*func)(), int priority) +bool icinga::InitializeOnceHelper(const std::function& func, int priority) { Loader::AddDeferredInitializer(func, priority); return true; diff --git a/lib/base/initialize.hpp b/lib/base/initialize.hpp index 0629abe68..446ad69af 100644 --- a/lib/base/initialize.hpp +++ b/lib/base/initialize.hpp @@ -4,6 +4,7 @@ #define INITIALIZE_H #include "base/i2-base.hpp" +#include 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& func, int priority = 0); #define INITIALIZE_ONCE(func) \ namespace { namespace I2_UNIQUE_NAME(io) { \