]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#883, !506] clean up code 883-create-thread-pool
authorRazvan Becheriu <razvan@isc.org>
Mon, 18 Nov 2019 17:56:35 +0000 (19:56 +0200)
committerRazvan Becheriu <razvan@isc.org>
Mon, 18 Nov 2019 17:56:35 +0000 (19:56 +0200)
src/lib/util/thread_pool.h

index 78544f8e577ecf33979206e9e4ae4faee6776cc6..6016d6bb0c4aad97be3176b544937178cd8a9f48 100644 (file)
@@ -63,18 +63,6 @@ struct ThreadPool {
         startInternal(thread_count);
     }
 
-    /// @brief start all the threads
-    ///
-    /// @param thread_count specifies the number of threads to be created and
-    /// started
-    void startInternal(uint32_t thread_count) {
-        queue_.enable();
-        running_ = true;
-        for (uint32_t i = 0; i < thread_count; ++i) {
-            threads_.push_back(std::make_shared<std::thread>(&ThreadPool::run, this));
-        }
-    }
-
     /// @brief stop all the threads
     ///
     /// @throw InvalidOperation if thread pool already stopped
@@ -85,16 +73,6 @@ struct ThreadPool {
         stopInternal();
     }
 
-    /// @brief stop all the threads
-    void stopInternal() {
-        running_ = false;
-        queue_.disable();
-        for (auto thread : threads_) {
-            thread->join();
-        }
-        threads_.clear();
-    }
-
     /// @brief add a work item to the thread pool
     ///
     /// @param item the 'function' object to be added to the queue
@@ -117,6 +95,28 @@ struct ThreadPool {
     }
 
 private:
+    /// @brief start all the threads
+    ///
+    /// @param thread_count specifies the number of threads to be created and
+    /// started
+    void startInternal(uint32_t thread_count) {
+        queue_.enable();
+        running_ = true;
+        for (uint32_t i = 0; i < thread_count; ++i) {
+            threads_.push_back(std::make_shared<std::thread>(&ThreadPool::run, this));
+        }
+    }
+
+    /// @brief stop all the threads
+    void stopInternal() {
+        running_ = false;
+        queue_.disable();
+        for (auto thread : threads_) {
+            thread->join();
+        }
+        threads_.clear();
+    }
+
     /// @brief Defines a generic thread pool queue.
     ///
     /// The main purpose is to safely manage thread pool tasks.