From 59492ae2e330abc5779e9d06e9f333cc4239f4ed Mon Sep 17 00:00:00 2001 From: MoonforDream <3052573970@qq.com> Date: Fri, 10 Jan 2025 23:21:38 +0800 Subject: [PATCH] update lfthreadpool.tpp --- src/lfthreadpool.tpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/lfthreadpool.tpp b/src/lfthreadpool.tpp index bfe8bea..4bd6baa 100644 --- a/src/lfthreadpool.tpp +++ b/src/lfthreadpool.tpp @@ -39,6 +39,19 @@ Author: MoonforDream namespace moon { + /** + * @brief Adds a new task to the thread pool. + * The task is assigned to a thread based on the current pool mode + * and load balancing. + * + * @tparam _Fn Function type of the task. + * @tparam _Args Variadic template for function arguments. + * @param fn Function representing the task. + * @param args Arguments to pass to the function. + * + * @return bool True if the task was added successfully, False if the pool + * is shutting down or if an error occurred. + */ template bool lfthreadpool::add_task(_Fn&& fn, _Args&&... args) { if (shutdown_.load(std::memory_order_acquire)) return false; @@ -49,6 +62,19 @@ namespace moon { return workers_[idx]->enqueue_task(f); } + /** + * @brief Adds a new task to the thread pool by moving it. + * This method is used to avoid copying when possible, enhancing + * performance. + * + * @tparam _Fn Function type of the task. + * @tparam _Args Variadic template for function arguments. + * @param fn Function representing the task. + * @param args Arguments to pass to the function. + * + * @return bool True if the task was added successfully, False if the pool + * is shutting down or if an error occurred. + */ template bool lfthreadpool::add_task_move(_Fn&& fn, _Args&&... args) { if (shutdown_.load(std::memory_order_acquire)) return false;