mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-29 08:34:20 +02:00
parent
b915494157
commit
7a3a8de83c
@ -51,12 +51,18 @@ void WorkQueue::Enqueue(const WorkCallback& item)
|
|||||||
|
|
||||||
ASSERT(!m_Stopped);
|
ASSERT(!m_Stopped);
|
||||||
|
|
||||||
if (boost::this_thread::get_id() != GetThreadId()) {
|
bool wq_thread = (boost::this_thread::get_id() == GetThreadId());
|
||||||
|
|
||||||
|
if (!wq_thread) {
|
||||||
while (m_Items.size() >= m_MaxItems)
|
while (m_Items.size() >= m_MaxItems)
|
||||||
m_CV.wait(lock);
|
m_CV.wait(lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Items.push_back(item);
|
m_Items.push_back(item);
|
||||||
|
|
||||||
|
if (wq_thread)
|
||||||
|
ProcessItems(lock);
|
||||||
|
else
|
||||||
m_CV.notify_all();
|
m_CV.notify_all();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,21 +93,9 @@ void WorkQueue::DefaultExceptionCallback(boost::exception_ptr exp)
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorkQueue::WorkerThreadProc(void)
|
void WorkQueue::ProcessItems(boost::mutex::scoped_lock& lock)
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock lock(m_Mutex);
|
while (!m_Items.empty()) {
|
||||||
|
|
||||||
std::ostringstream idbuf;
|
|
||||||
idbuf << "WQ #" << m_ID;
|
|
||||||
Utility::SetThreadName(idbuf.str());
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
while (m_Items.empty() && !m_Joined)
|
|
||||||
m_CV.wait(lock);
|
|
||||||
|
|
||||||
if (m_Joined)
|
|
||||||
break;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
WorkCallback wi = m_Items.front();
|
WorkCallback wi = m_Items.front();
|
||||||
m_Items.pop_front();
|
m_Items.pop_front();
|
||||||
@ -121,6 +115,25 @@ void WorkQueue::WorkerThreadProc(void)
|
|||||||
|
|
||||||
lock.lock();
|
lock.lock();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorkQueue::WorkerThreadProc(void)
|
||||||
|
{
|
||||||
|
boost::mutex::scoped_lock lock(m_Mutex);
|
||||||
|
|
||||||
|
std::ostringstream idbuf;
|
||||||
|
idbuf << "WQ #" << m_ID;
|
||||||
|
Utility::SetThreadName(idbuf.str());
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
while (m_Items.empty() && !m_Joined)
|
||||||
|
m_CV.wait(lock);
|
||||||
|
|
||||||
|
if (m_Joined)
|
||||||
|
break;
|
||||||
|
|
||||||
|
ProcessItems(lock);
|
||||||
|
}
|
||||||
|
|
||||||
m_Stopped = true;
|
m_Stopped = true;
|
||||||
m_CV.notify_all();
|
m_CV.notify_all();
|
||||||
|
@ -65,6 +65,7 @@ private:
|
|||||||
std::deque<WorkCallback> m_Items;
|
std::deque<WorkCallback> m_Items;
|
||||||
ExceptionCallback m_ExceptionCallback;
|
ExceptionCallback m_ExceptionCallback;
|
||||||
|
|
||||||
|
void ProcessItems(boost::mutex::scoped_lock& lock);
|
||||||
void WorkerThreadProc(void);
|
void WorkerThreadProc(void);
|
||||||
|
|
||||||
static void DefaultExceptionCallback(boost::exception_ptr exp);
|
static void DefaultExceptionCallback(boost::exception_ptr exp);
|
||||||
|
@ -52,23 +52,15 @@ void HostGroupDbObject::OnConfigUpdate(void)
|
|||||||
{
|
{
|
||||||
HostGroup::Ptr group = static_pointer_cast<HostGroup>(GetObject());
|
HostGroup::Ptr group = static_pointer_cast<HostGroup>(GetObject());
|
||||||
|
|
||||||
|
BOOST_FOREACH(const Host::Ptr& host, group->GetMembers()) {
|
||||||
DbQuery query1;
|
DbQuery query1;
|
||||||
query1.Table = DbType::GetByName("HostGroup")->GetTable() + "_members";
|
query1.Table = DbType::GetByName("HostGroup")->GetTable() + "_members";
|
||||||
query1.Type = DbQueryDelete;
|
query1.Type = DbQueryInsert;
|
||||||
query1.Category = DbCatConfig;
|
query1.Category = DbCatConfig;
|
||||||
query1.WhereCriteria = make_shared<Dictionary>();
|
query1.Fields = make_shared<Dictionary>();
|
||||||
query1.WhereCriteria->Set("hostgroup_id", DbValue::FromObjectInsertID(group));
|
query1.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||||
|
query1.Fields->Set("hostgroup_id", DbValue::FromObjectInsertID(group));
|
||||||
|
query1.Fields->Set("host_object_id", host);
|
||||||
OnQuery(query1);
|
OnQuery(query1);
|
||||||
|
|
||||||
BOOST_FOREACH(const Host::Ptr& host, group->GetMembers()) {
|
|
||||||
DbQuery query2;
|
|
||||||
query2.Table = DbType::GetByName("HostGroup")->GetTable() + "_members";
|
|
||||||
query2.Type = DbQueryInsert;
|
|
||||||
query2.Category = DbCatConfig;
|
|
||||||
query2.Fields = make_shared<Dictionary>();
|
|
||||||
query2.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
|
||||||
query2.Fields->Set("hostgroup_id", DbValue::FromObjectInsertID(group));
|
|
||||||
query2.Fields->Set("host_object_id", host);
|
|
||||||
OnQuery(query2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,23 +51,15 @@ void ServiceGroupDbObject::OnConfigUpdate(void)
|
|||||||
{
|
{
|
||||||
ServiceGroup::Ptr group = static_pointer_cast<ServiceGroup>(GetObject());
|
ServiceGroup::Ptr group = static_pointer_cast<ServiceGroup>(GetObject());
|
||||||
|
|
||||||
|
BOOST_FOREACH(const Service::Ptr& service, group->GetMembers()) {
|
||||||
DbQuery query1;
|
DbQuery query1;
|
||||||
query1.Table = DbType::GetByName("ServiceGroup")->GetTable() + "_members";
|
query1.Table = DbType::GetByName("ServiceGroup")->GetTable() + "_members";
|
||||||
query1.Type = DbQueryDelete;
|
query1.Type = DbQueryInsert;
|
||||||
query1.Category = DbCatConfig;
|
query1.Category = DbCatConfig;
|
||||||
query1.WhereCriteria = make_shared<Dictionary>();
|
query1.Fields = make_shared<Dictionary>();
|
||||||
query1.WhereCriteria->Set("servicegroup_id", DbValue::FromObjectInsertID(group));
|
query1.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||||
|
query1.Fields->Set("servicegroup_id", DbValue::FromObjectInsertID(group));
|
||||||
|
query1.Fields->Set("service_object_id", service);
|
||||||
OnQuery(query1);
|
OnQuery(query1);
|
||||||
|
|
||||||
BOOST_FOREACH(const Service::Ptr& service, group->GetMembers()) {
|
|
||||||
DbQuery query2;
|
|
||||||
query2.Table = DbType::GetByName("ServiceGroup")->GetTable() + "_members";
|
|
||||||
query2.Type = DbQueryInsert;
|
|
||||||
query2.Category = DbCatConfig;
|
|
||||||
query2.Fields = make_shared<Dictionary>();
|
|
||||||
query2.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
|
||||||
query2.Fields->Set("servicegroup_id", DbValue::FromObjectInsertID(group));
|
|
||||||
query2.Fields->Set("service_object_id", service);
|
|
||||||
OnQuery(query2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user