2019-02-25 14:48:22 +01:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2015-03-18 13:24:31 +01:00
|
|
|
|
|
|
|
#include "base/loader.hpp"
|
2018-01-01 15:21:14 +01:00
|
|
|
#include "base/logger.hpp"
|
|
|
|
#include "base/exception.hpp"
|
|
|
|
#include "base/application.hpp"
|
2015-03-18 13:24:31 +01:00
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
2022-12-12 13:08:41 +01:00
|
|
|
boost::thread_specific_ptr<Loader::DeferredInitializerPriorityQueue>& Loader::GetDeferredInitializers()
|
2015-03-18 13:24:31 +01:00
|
|
|
{
|
2022-12-12 13:08:41 +01:00
|
|
|
static boost::thread_specific_ptr<DeferredInitializerPriorityQueue> initializers;
|
2015-03-18 13:24:31 +01:00
|
|
|
return initializers;
|
|
|
|
}
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
void Loader::ExecuteDeferredInitializers()
|
2015-03-18 13:24:31 +01:00
|
|
|
{
|
2022-08-26 17:21:12 +02:00
|
|
|
auto& initializers = GetDeferredInitializers();
|
|
|
|
if (!initializers.get())
|
2015-03-18 13:24:31 +01:00
|
|
|
return;
|
|
|
|
|
2022-08-26 17:21:12 +02:00
|
|
|
while (!initializers->empty()) {
|
|
|
|
DeferredInitializer initializer = initializers->top();
|
|
|
|
initializers->pop();
|
2015-03-18 13:24:31 +01:00
|
|
|
initializer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-12 12:32:59 +01:00
|
|
|
void Loader::AddDeferredInitializer(const std::function<void()>& callback, InitializePriority priority)
|
2015-03-18 13:24:31 +01:00
|
|
|
{
|
2022-08-26 17:21:12 +02:00
|
|
|
auto& initializers = GetDeferredInitializers();
|
|
|
|
if (!initializers.get()) {
|
|
|
|
initializers.reset(new Loader::DeferredInitializerPriorityQueue());
|
|
|
|
}
|
2015-03-18 13:24:31 +01:00
|
|
|
|
2022-08-26 17:21:12 +02:00
|
|
|
initializers->push(DeferredInitializer(callback, priority));
|
2015-03-18 13:24:31 +01:00
|
|
|
}
|
|
|
|
|