mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-20 04:04:32 +02:00
InitializePriority: don't explicitly specify values
Now that all values are in one place, there is no reason for this numbering with gaps anymore. If you need to insert a new value in between, you can just do so in the enum. This reverses the sort order of the enum, thereby requiring a change to the sort order of the std::priority_queue containing the elements.
This commit is contained in:
parent
99bb687350
commit
6229f4d9bf
@ -9,17 +9,22 @@
|
|||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Priority values for use with the INITIALIZE_ONCE_WITH_PRIORITY macro.
|
||||||
|
*
|
||||||
|
* The values are given in the order of initialization.
|
||||||
|
*/
|
||||||
enum class InitializePriority {
|
enum class InitializePriority {
|
||||||
CreateNamespaces = 1000,
|
CreateNamespaces,
|
||||||
InitIcingaApplication = 50,
|
InitIcingaApplication,
|
||||||
RegisterTypeType = 20,
|
RegisterTypeType,
|
||||||
RegisterObjectType = 20,
|
RegisterObjectType,
|
||||||
RegisterPrimitiveTypes = 15,
|
RegisterPrimitiveTypes,
|
||||||
RegisterBuiltinTypes = 15,
|
RegisterBuiltinTypes,
|
||||||
RegisterFunctions = 10,
|
RegisterFunctions,
|
||||||
RegisterTypes = 10,
|
RegisterTypes,
|
||||||
EvaluateConfigFragments = 5,
|
EvaluateConfigFragments,
|
||||||
Default = 0,
|
Default,
|
||||||
};
|
};
|
||||||
|
|
||||||
#define I2_TOKENPASTE(x, y) x ## y
|
#define I2_TOKENPASTE(x, y) x ## y
|
||||||
|
@ -7,9 +7,9 @@
|
|||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
boost::thread_specific_ptr<std::priority_queue<DeferredInitializer> >& Loader::GetDeferredInitializers()
|
boost::thread_specific_ptr<Loader::DeferredInitializerPriorityQueue>& Loader::GetDeferredInitializers()
|
||||||
{
|
{
|
||||||
static boost::thread_specific_ptr<std::priority_queue<DeferredInitializer> > initializers;
|
static boost::thread_specific_ptr<DeferredInitializerPriorityQueue> initializers;
|
||||||
return initializers;
|
return initializers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ void Loader::ExecuteDeferredInitializers()
|
|||||||
void Loader::AddDeferredInitializer(const std::function<void()>& callback, InitializePriority priority)
|
void Loader::AddDeferredInitializer(const std::function<void()>& callback, InitializePriority priority)
|
||||||
{
|
{
|
||||||
if (!GetDeferredInitializers().get())
|
if (!GetDeferredInitializers().get())
|
||||||
GetDeferredInitializers().reset(new std::priority_queue<DeferredInitializer>());
|
GetDeferredInitializers().reset(new Loader::DeferredInitializerPriorityQueue());
|
||||||
|
|
||||||
GetDeferredInitializers().get()->push(DeferredInitializer(callback, priority));
|
GetDeferredInitializers().get()->push(DeferredInitializer(callback, priority));
|
||||||
}
|
}
|
||||||
|
@ -19,9 +19,9 @@ public:
|
|||||||
: m_Callback(std::move(callback)), m_Priority(priority)
|
: m_Callback(std::move(callback)), m_Priority(priority)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
bool operator<(const DeferredInitializer& other) const
|
bool operator>(const DeferredInitializer& other) const
|
||||||
{
|
{
|
||||||
return m_Priority < other.m_Priority;
|
return m_Priority > other.m_Priority;
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator()()
|
void operator()()
|
||||||
@ -48,7 +48,12 @@ public:
|
|||||||
private:
|
private:
|
||||||
Loader();
|
Loader();
|
||||||
|
|
||||||
static boost::thread_specific_ptr<std::priority_queue<DeferredInitializer> >& GetDeferredInitializers();
|
// Deferred initializers are run in the order of the definition of their enum values.
|
||||||
|
// Therefore, initializers that should be run first have lower enum values and
|
||||||
|
// the order of the std::priority_queue has to be reversed using std::greater.
|
||||||
|
using DeferredInitializerPriorityQueue = std::priority_queue<DeferredInitializer, std::vector<DeferredInitializer>, std::greater<>>;
|
||||||
|
|
||||||
|
static boost::thread_specific_ptr<DeferredInitializerPriorityQueue>& GetDeferredInitializers();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user