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;
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
boost::thread_specific_ptr<std::priority_queue<DeferredInitializer> >& Loader::GetDeferredInitializers()
|
2015-03-18 13:24:31 +01:00
|
|
|
{
|
|
|
|
static boost::thread_specific_ptr<std::priority_queue<DeferredInitializer> > initializers;
|
|
|
|
return initializers;
|
|
|
|
}
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
void Loader::ExecuteDeferredInitializers()
|
2015-03-18 13:24:31 +01:00
|
|
|
{
|
|
|
|
if (!GetDeferredInitializers().get())
|
|
|
|
return;
|
|
|
|
|
|
|
|
while (!GetDeferredInitializers().get()->empty()) {
|
|
|
|
DeferredInitializer initializer = GetDeferredInitializers().get()->top();
|
|
|
|
GetDeferredInitializers().get()->pop();
|
|
|
|
initializer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
void Loader::AddDeferredInitializer(const std::function<void()>& callback, int priority)
|
2015-03-18 13:24:31 +01:00
|
|
|
{
|
|
|
|
if (!GetDeferredInitializers().get())
|
|
|
|
GetDeferredInitializers().reset(new std::priority_queue<DeferredInitializer>());
|
|
|
|
|
|
|
|
GetDeferredInitializers().get()->push(DeferredInitializer(callback, priority));
|
|
|
|
}
|
|
|
|
|