]> granicus.if.org Git - icinga2/commitdiff
Apply clang-tidy fix 'modernize-loop-convert'
authorGunnar Beutner <gunnar.beutner@icinga.com>
Thu, 4 Jan 2018 07:15:20 +0000 (08:15 +0100)
committerGunnar Beutner <gunnar.beutner@icinga.com>
Thu, 4 Jan 2018 11:24:57 +0000 (12:24 +0100)
lib/base/process.cpp
lib/base/threadpool.cpp
lib/db_ido/dbconnection.cpp
tools/mkclass/classcompiler.hpp

index d8c381c7f76dd3a042b2b13948fc64a660052dc9..fef953ddef27774be4cc45687c3c2b0230d05f36 100644 (file)
@@ -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()
index cca32652d1a529a01bd0bff3c03874ee66e142a0..4872652ec7b71f0a0c5750b818e47286bb15d71d 100644 (file)
@@ -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;
index fd1581f16b3f31f409dfeaffd42b19ef389560f5..ddbf76ff36643ea63c069b5632862527327f06ab 100644 (file)
@@ -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;
        }
index f4b8f0ba9a9b2ecfc4a6d772792d14243849ba2c..67a50070d08b1595ba351aca2d476cda6ce9d157 100644 (file)
@@ -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;
                        }
                }