From: Razvan Becheriu Date: Mon, 18 Nov 2019 17:56:35 +0000 (+0200) Subject: [#883, !506] clean up code X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2F883-create-thread-pool;p=thirdparty%2Fkea.git [#883, !506] clean up code --- diff --git a/src/lib/util/thread_pool.h b/src/lib/util/thread_pool.h index 78544f8e57..6016d6bb0c 100644 --- a/src/lib/util/thread_pool.h +++ b/src/lib/util/thread_pool.h @@ -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(&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(&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.