]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1599] fixed register/unregister thread in ThreadPoolQueue
authorRazvan Becheriu <razvan@isc.org>
Thu, 10 Dec 2020 21:19:28 +0000 (23:19 +0200)
committerRazvan Becheriu <razvan@isc.org>
Wed, 15 Nov 2023 06:36:55 +0000 (08:36 +0200)
src/lib/util/thread_pool.h

index 48d2042b180c778867ef83c17a4b0e19d3c9d71a..9448d021ef93c6c53e30794b0cdf2aaa2408ebad 100644 (file)
@@ -259,6 +259,12 @@ private:
             ++working_;
         }
 
+        /// @brief unregister thread so that it can be ignored
+        void unregisterThread() {
+            std::lock_guard<std::mutex> lock(mutex_);
+            --working_;
+        }
+
         /// @brief set maximum number of work items in the queue
         ///
         /// @return the maximum size (0 means unlimited)
@@ -349,10 +355,10 @@ private:
                 wait_cv_.notify_all();
             }
             cv_.wait(lock, [&]() {return (!enabled_ || !queue_.empty());});
+            ++working_;
             if (!enabled_) {
                 return (Item());
             }
-            ++working_;
             size_t length = queue_.size();
             stat10 = stat10 * CEXP10 + (1 - CEXP10) * length;
             stat100 = stat100 * CEXP100 + (1 - CEXP100) * length;
@@ -506,6 +512,9 @@ private:
                 }
             }
         }
+        if (!register_thread) {
+            queue_.unregisterThread();
+        }
     }
 
     /// @brief list of worker threads