mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-27 07:34:15 +02:00
Apply clang-tidy fix 'modernize-loop-convert'
This commit is contained in:
parent
9ca682496c
commit
6da7d48d25
@ -506,7 +506,7 @@ void Process::InitializeSpawnHelper()
|
|||||||
|
|
||||||
static void InitializeProcess()
|
static void InitializeProcess()
|
||||||
{
|
{
|
||||||
for (int tid = 0; tid < IOTHREADS; tid++) {
|
for (auto& l_EventFD : l_EventFDs) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
l_Events[tid] = CreateEvent(nullptr, TRUE, FALSE, nullptr);
|
l_Events[tid] = CreateEvent(nullptr, TRUE, FALSE, nullptr);
|
||||||
#else /* _WIN32 */
|
#else /* _WIN32 */
|
||||||
@ -514,14 +514,14 @@ static void InitializeProcess()
|
|||||||
if (pipe2(l_EventFDs[tid], O_CLOEXEC) < 0) {
|
if (pipe2(l_EventFDs[tid], O_CLOEXEC) < 0) {
|
||||||
if (errno == ENOSYS) {
|
if (errno == ENOSYS) {
|
||||||
# endif /* HAVE_PIPE2 */
|
# endif /* HAVE_PIPE2 */
|
||||||
if (pipe(l_EventFDs[tid]) < 0) {
|
if (pipe(l_EventFD) < 0) {
|
||||||
BOOST_THROW_EXCEPTION(posix_error()
|
BOOST_THROW_EXCEPTION(posix_error()
|
||||||
<< boost::errinfo_api_function("pipe")
|
<< boost::errinfo_api_function("pipe")
|
||||||
<< boost::errinfo_errno(errno));
|
<< boost::errinfo_errno(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
Utility::SetCloExec(l_EventFDs[tid][0]);
|
Utility::SetCloExec(l_EventFD[0]);
|
||||||
Utility::SetCloExec(l_EventFDs[tid][1]);
|
Utility::SetCloExec(l_EventFD[1]);
|
||||||
# ifdef HAVE_PIPE2
|
# ifdef HAVE_PIPE2
|
||||||
} else {
|
} else {
|
||||||
BOOST_THROW_EXCEPTION(posix_error()
|
BOOST_THROW_EXCEPTION(posix_error()
|
||||||
|
@ -50,8 +50,8 @@ void ThreadPool::Start()
|
|||||||
|
|
||||||
m_Stopped = false;
|
m_Stopped = false;
|
||||||
|
|
||||||
for (size_t i = 0; i < sizeof(m_Queues) / sizeof(m_Queues[0]); i++)
|
for (auto& queue : m_Queues)
|
||||||
m_Queues[i].SpawnWorker(m_ThreadGroup);
|
queue.SpawnWorker(m_ThreadGroup);
|
||||||
|
|
||||||
m_MgmtThread = std::thread(std::bind(&ThreadPool::ManagerThreadProc, this));
|
m_MgmtThread = std::thread(std::bind(&ThreadPool::ManagerThreadProc, this));
|
||||||
}
|
}
|
||||||
@ -70,18 +70,18 @@ void ThreadPool::Stop()
|
|||||||
if (m_MgmtThread.joinable())
|
if (m_MgmtThread.joinable())
|
||||||
m_MgmtThread.join();
|
m_MgmtThread.join();
|
||||||
|
|
||||||
for (size_t i = 0; i < sizeof(m_Queues) / sizeof(m_Queues[0]); i++) {
|
for (auto& queue : m_Queues) {
|
||||||
boost::mutex::scoped_lock lock(m_Queues[i].Mutex);
|
boost::mutex::scoped_lock lock(queue.Mutex);
|
||||||
m_Queues[i].Stopped = true;
|
queue.Stopped = true;
|
||||||
m_Queues[i].CV.notify_all();
|
queue.CV.notify_all();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_ThreadGroup.join_all();
|
m_ThreadGroup.join_all();
|
||||||
m_ThreadGroup.~thread_group();
|
m_ThreadGroup.~thread_group();
|
||||||
new (&m_ThreadGroup) boost::thread_group();
|
new (&m_ThreadGroup) boost::thread_group();
|
||||||
|
|
||||||
for (size_t i = 0; i < sizeof(m_Queues) / sizeof(m_Queues[0]); i++)
|
for (auto& queue : m_Queues)
|
||||||
m_Queues[i].Stopped = false;
|
queue.Stopped = false;
|
||||||
|
|
||||||
m_Stopped = true;
|
m_Stopped = true;
|
||||||
}
|
}
|
||||||
@ -242,24 +242,22 @@ void ThreadPool::ManagerThreadProc()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < sizeof(m_Queues) / sizeof(m_Queues[0]); i++) {
|
for (auto& queue : m_Queues) {
|
||||||
size_t pending, alive = 0;
|
size_t pending, alive = 0;
|
||||||
double avg_latency;
|
double avg_latency;
|
||||||
double utilization = 0;
|
double utilization = 0;
|
||||||
|
|
||||||
Queue& queue = m_Queues[i];
|
|
||||||
|
|
||||||
boost::mutex::scoped_lock lock(queue.Mutex);
|
boost::mutex::scoped_lock lock(queue.Mutex);
|
||||||
|
|
||||||
for (size_t i = 0; i < sizeof(queue.Threads) / sizeof(queue.Threads[0]); i++)
|
for (auto& thread : queue.Threads)
|
||||||
queue.Threads[i].UpdateUtilization();
|
thread.UpdateUtilization();
|
||||||
|
|
||||||
pending = queue.Items.size();
|
pending = queue.Items.size();
|
||||||
|
|
||||||
for (size_t i = 0; i < sizeof(queue.Threads) / sizeof(queue.Threads[0]); i++) {
|
for (auto& thread : queue.Threads) {
|
||||||
if (queue.Threads[i].State != ThreadDead && !queue.Threads[i].Zombie) {
|
if (thread.State != ThreadDead && !thread.Zombie) {
|
||||||
alive++;
|
alive++;
|
||||||
utilization += queue.Threads[i].Utilization * 100;
|
utilization += thread.Utilization * 100;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -331,12 +329,12 @@ void ThreadPool::ManagerThreadProc()
|
|||||||
*/
|
*/
|
||||||
void ThreadPool::Queue::SpawnWorker(boost::thread_group& group)
|
void ThreadPool::Queue::SpawnWorker(boost::thread_group& group)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < sizeof(Threads) / sizeof(Threads[0]); i++) {
|
for (auto& thread : Threads) {
|
||||||
if (Threads[i].State == ThreadDead) {
|
if (thread.State == ThreadDead) {
|
||||||
Log(LogDebug, "ThreadPool", "Spawning worker thread.");
|
Log(LogDebug, "ThreadPool", "Spawning worker thread.");
|
||||||
|
|
||||||
Threads[i] = WorkerThread(ThreadIdle);
|
thread = WorkerThread(ThreadIdle);
|
||||||
Threads[i].Thread = group.create_thread(std::bind(&ThreadPool::WorkerThread::ThreadProc, std::ref(Threads[i]), std::ref(*this)));
|
thread.Thread = group.create_thread(std::bind(&ThreadPool::WorkerThread::ThreadProc, std::ref(thread), std::ref(*this)));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -348,15 +346,15 @@ void ThreadPool::Queue::SpawnWorker(boost::thread_group& group)
|
|||||||
*/
|
*/
|
||||||
void ThreadPool::Queue::KillWorker(boost::thread_group& group)
|
void ThreadPool::Queue::KillWorker(boost::thread_group& group)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < sizeof(Threads) / sizeof(Threads[0]); i++) {
|
for (auto& thread : Threads) {
|
||||||
if (Threads[i].State == ThreadIdle && !Threads[i].Zombie) {
|
if (thread.State == ThreadIdle && !thread.Zombie) {
|
||||||
Log(LogDebug, "ThreadPool", "Killing worker thread.");
|
Log(LogDebug, "ThreadPool", "Killing worker thread.");
|
||||||
|
|
||||||
group.remove_thread(Threads[i].Thread);
|
group.remove_thread(thread.Thread);
|
||||||
Threads[i].Thread->detach();
|
thread.Thread->detach();
|
||||||
delete Threads[i].Thread;
|
delete thread.Thread;
|
||||||
|
|
||||||
Threads[i].Zombie = true;
|
thread.Zombie = true;
|
||||||
CV.notify_all();
|
CV.notify_all();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -229,15 +229,15 @@ void DbConnection::CleanUpHandler()
|
|||||||
{ "systemcommands", "start_time" }
|
{ "systemcommands", "start_time" }
|
||||||
};
|
};
|
||||||
|
|
||||||
for (size_t i = 0; i < sizeof(tables) / sizeof(tables[0]); i++) {
|
for (auto& table : tables) {
|
||||||
double max_age = GetCleanup()->Get(tables[i].name + "_age");
|
double max_age = GetCleanup()->Get(table.name + "_age");
|
||||||
|
|
||||||
if (max_age == 0)
|
if (max_age == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
CleanUpExecuteQuery(tables[i].name, tables[i].time_column, now - max_age);
|
CleanUpExecuteQuery(table.name, table.time_column, now - max_age);
|
||||||
Log(LogNotice, "DbConnection")
|
Log(LogNotice, "DbConnection")
|
||||||
<< "Cleanup (" << tables[i].name << "): " << max_age
|
<< "Cleanup (" << table.name << "): " << max_age
|
||||||
<< " now: " << now
|
<< " now: " << now
|
||||||
<< " old: " << now - max_age;
|
<< " old: " << now - max_age;
|
||||||
}
|
}
|
||||||
|
@ -138,14 +138,14 @@ struct Field
|
|||||||
bool cap = true;
|
bool cap = true;
|
||||||
std::string name = Name;
|
std::string name = Name;
|
||||||
|
|
||||||
for (size_t i = 0; i < name.size(); i++) {
|
for (char& ch : name) {
|
||||||
if (name[i] == '_') {
|
if (ch == '_') {
|
||||||
cap = true;
|
cap = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cap) {
|
if (cap) {
|
||||||
name[i] = toupper(name[i]);
|
ch = toupper(ch);
|
||||||
cap = false;
|
cap = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user