1
0
mirror of https://github.com/Icinga/icinga2.git synced 2025-04-07 20:25:08 +02:00

Clean up the code a bit

This commit is contained in:
Gunnar Beutner 2014-11-11 23:06:47 +01:00
parent 9932f60522
commit ee980a788b
7 changed files with 49 additions and 36 deletions

@ -28,7 +28,9 @@ using namespace icinga;
DynamicType::DynamicType(const String& name)
: m_Name(name)
{ }
{
InflateMutex();
}
DynamicType::Ptr DynamicType::GetByName(const String& name)
{

@ -59,6 +59,11 @@ bool Object::OwnsLock(void) const
}
#endif /* _DEBUG */
void Object::InflateMutex(void)
{
m_Mutex.Inflate();
}
void Object::SetField(int, const Value&)
{
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid field ID."));

@ -99,6 +99,8 @@ public:
bool OwnsLock(void) const;
#endif /* _DEBUG */
void InflateMutex(void);
private:
Object(const Object& other);
Object& operator=(const Object& rhs);

@ -67,26 +67,7 @@ public:
#endif /* _DEBUG */
}
inline void Spin(unsigned int it)
{
if (it < 8) {
/* Do nothing. */
}
#ifdef SPIN_PAUSE
else if (it < 16) {
SPIN_PAUSE();
}
#endif /* SPIN_PAUSE */
else {
#ifdef _WIN32
Sleep(0);
#else /* _WIN32 */
sched_yield();
#endif /* _WIN32 */
}
}
inline void Lock(void)
inline void Lock(bool make_native = false)
{
bool contended = false;
unsigned int it = 0;
@ -111,16 +92,10 @@ public:
it++;
}
if (contended)
if (contended || make_native)
MakeNative();
}
void MakeNative(void);
void DestroyNative(void);
void LockNative(void);
void UnlockNative(void);
inline void Unlock(void)
{
#ifdef _WIN32
@ -135,10 +110,43 @@ public:
UnlockNative();
}
inline void Inflate(void)
{
Lock(true);
Unlock();
}
#ifdef _DEBUG
static void DebugTimerHandler(void);
#endif /* _DEBUG */
private:
inline void Spin(unsigned int it)
{
if (it < 8) {
/* Do nothing. */
}
#ifdef SPIN_PAUSE
else if (it < 16) {
SPIN_PAUSE();
}
#endif /* SPIN_PAUSE */
else {
#ifdef _WIN32
DebugBreak();
Sleep(0);
#else /* _WIN32 */
sched_yield();
#endif /* _WIN32 */
}
}
void MakeNative(void);
void DestroyNative(void);
void LockNative(void);
void UnlockNative(void);
private:
#ifdef _WIN32
# ifdef _WIN64

@ -137,9 +137,7 @@ DynamicObject::Ptr ConfigItem::Commit(bool discard)
/* Make sure the type is valid. */
Type::Ptr type = Type::GetByName(GetType());
if (!type || !Type::GetByName("DynamicObject")->IsAssignableFrom(type))
BOOST_THROW_EXCEPTION(ConfigError("Type '" + GetType() + "' does not exist."));
ASSERT(type && Type::GetByName("DynamicObject")->IsAssignableFrom(type));
if (IsAbstract())
return DynamicObject::Ptr();
@ -156,6 +154,7 @@ DynamicObject::Ptr ConfigItem::Commit(bool discard)
locals->Set("name", m_Name);
dobj->SetParentScope(locals);
locals.reset();
DebugHint debugHints;
@ -171,7 +170,7 @@ DynamicObject::Ptr ConfigItem::Commit(bool discard)
if (discard)
m_Expression.reset();
dobj->SetParentScope(Dictionary::Ptr());
dobj->SetParentScope(Object::Ptr());
String name = m_Name;
@ -199,6 +198,7 @@ DynamicObject::Ptr ConfigItem::Commit(bool discard)
persistentItem->Set("debug_hints", debugHints.ToDictionary());
ConfigCompilerContext::GetInstance()->WriteObject(persistentItem);
persistentItem.reset();
ConfigType::Ptr ctype = ConfigType::GetByName(GetType());

@ -71,8 +71,6 @@ private:
bool m_Abstract; /**< Whether this is a template. */
boost::shared_ptr<Expression> m_Expression;
std::vector<String> m_ParentNames; /**< The names of parent configuration
items. */
DebugInfo m_DebugInfo; /**< Debug information. */
Object::Ptr m_Scope; /**< variable scope. */
String m_Zone; /**< The zone. */

@ -68,8 +68,6 @@ void ConfigType::AddParentRules(std::vector<TypeRuleList::Ptr>& ruleLists, const
if (parent) {
AddParentRules(ruleLists, parent);
ObjectLock plock(parent);
ruleLists.push_back(parent->m_RuleList);
}
}