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