Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lib/base/objectlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,24 @@ ObjectLock::ObjectLock(const Object *object)
Lock();
}

/**
* Tries to lock the object without blocking.
*
* @returns true if the lock was acquired, false otherwise.
*/
bool ObjectLock::TryLock() noexcept
{
ASSERT(!m_Locked && m_Object);

m_Locked = m_Object->m_Mutex.try_lock();
#ifdef I2_DEBUG
if (m_Locked && ++m_Object->m_LockCount == 1u) {
m_Object->m_LockOwner.store(std::this_thread::get_id());
}
#endif /* I2_DEBUG */
return m_Locked;
}

void ObjectLock::Lock()
{
ASSERT(!m_Locked && m_Object);
Expand Down
1 change: 1 addition & 0 deletions lib/base/objectlock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ struct ObjectLock

~ObjectLock();

bool TryLock() noexcept;
void Lock();
void Unlock();

Expand Down
9 changes: 0 additions & 9 deletions lib/checker/checkercomponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,13 @@ void CheckerComponent::CheckThreadProc()

bool forced = checkable->GetForceNextCheck();
bool check = true;
bool notifyNextCheck = false;
double nextCheck = -1;

if (!forced) {
if (!checkable->IsReachable(DependencyCheckExecution)) {
Log(LogNotice, "CheckerComponent")
<< "Skipping check for object '" << checkable->GetName() << "': Dependency failed.";

check = false;
notifyNextCheck = true;
}

Host::Ptr host;
Expand Down Expand Up @@ -181,7 +178,6 @@ void CheckerComponent::CheckThreadProc()
<< Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", nextCheck);

check = false;
notifyNextCheck = true;
}
}
}
Expand All @@ -200,11 +196,6 @@ void CheckerComponent::CheckThreadProc()
checkable->UpdateNextCheck();
}

if (notifyNextCheck) {
// Trigger update event for Icinga DB
Checkable::OnNextCheckUpdated(checkable);
}

lock.lock();

continue;
Expand Down
16 changes: 16 additions & 0 deletions lib/icinga/dependency-group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,22 @@ void DependencyGroup::LoadParents(std::set<Checkable::Ptr>& parents) const
}
}

/**
* Retrieve any child Checkable from the current dependency group.
*
* @return - Returns the first child Checkable found in this group, or nullptr if there are no children.
*/
Checkable::Ptr DependencyGroup::GetAnyChild() const
{
std::lock_guard lock(m_Mutex);
for (auto& [_, children] : m_Members) {
if (!children.empty()) {
return children.begin()->second->GetChild();
}
}
return nullptr;
}

/**
* Retrieve the number of dependency objects in the current dependency group.
*
Expand Down
1 change: 1 addition & 0 deletions lib/icinga/dependency.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class DependencyGroup final : public SharedObject
void RemoveDependency(const Dependency::Ptr& dependency);
std::vector<Dependency::Ptr> GetDependenciesForChild(const Checkable* child) const;
void LoadParents(std::set<Checkable::Ptr>& parents) const;
Checkable::Ptr GetAnyChild() const;
size_t GetDependenciesCount() const;

void SetIcingaDBIdentifier(const String& identifier);
Expand Down
2 changes: 1 addition & 1 deletion lib/icingadb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mkclass_target(icingadb.ti icingadb-ti.cpp icingadb-ti.hpp)
mkembedconfig_target(icingadb-itl.conf icingadb-itl.cpp)

set(icingadb_SOURCES
icingadb.cpp icingadb-objects.cpp icingadb-stats.cpp icingadb-utility.cpp redisconnection.cpp icingadb-ti.hpp
icingadb.cpp icingadb-objects.cpp icingadb-stats.cpp icingadb-utility.cpp icingadb-worker.cpp redisconnection.cpp icingadb-ti.hpp
icingadbchecktask.cpp icingadb-itl.cpp
)

Expand Down
Loading
Loading