mirror of
https://github.com/Icinga/icinga2.git
synced 2025-04-08 17:05:25 +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
|
||||
{
|
||||
|
||||
/**
|
||||
* Priority values for use with the INITIALIZE_ONCE_WITH_PRIORITY macro.
|
||||
*
|
||||
* The values are given in the order of initialization.
|
||||
*/
|
||||
enum class InitializePriority {
|
||||
CreateNamespaces = 1000,
|
||||
InitIcingaApplication = 50,
|
||||
RegisterTypeType = 20,
|
||||
RegisterObjectType = 20,
|
||||
RegisterPrimitiveTypes = 15,
|
||||
RegisterBuiltinTypes = 15,
|
||||
RegisterFunctions = 10,
|
||||
RegisterTypes = 10,
|
||||
EvaluateConfigFragments = 5,
|
||||
Default = 0,
|
||||
CreateNamespaces,
|
||||
InitIcingaApplication,
|
||||
RegisterTypeType,
|
||||
RegisterObjectType,
|
||||
RegisterPrimitiveTypes,
|
||||
RegisterBuiltinTypes,
|
||||
RegisterFunctions,
|
||||
RegisterTypes,
|
||||
EvaluateConfigFragments,
|
||||
Default,
|
||||
};
|
||||
|
||||
#define I2_TOKENPASTE(x, y) x ## y
|
||||
|
@ -7,9 +7,9 @@
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ void Loader::ExecuteDeferredInitializers()
|
||||
void Loader::AddDeferredInitializer(const std::function<void()>& callback, InitializePriority priority)
|
||||
{
|
||||
if (!GetDeferredInitializers().get())
|
||||
GetDeferredInitializers().reset(new std::priority_queue<DeferredInitializer>());
|
||||
GetDeferredInitializers().reset(new Loader::DeferredInitializerPriorityQueue());
|
||||
|
||||
GetDeferredInitializers().get()->push(DeferredInitializer(callback, priority));
|
||||
}
|
||||
|
@ -19,9 +19,9 @@ public:
|
||||
: 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()()
|
||||
@ -48,7 +48,12 @@ public:
|
||||
private:
|
||||
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