Skip to content

Commit

Permalink
update lfthreadpool.tpp
Browse files Browse the repository at this point in the history
  • Loading branch information
MoonforDream committed Jan 10, 2025
1 parent d088122 commit 59492ae
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/lfthreadpool.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename _Fn, typename... _Args>
bool lfthreadpool::add_task(_Fn&& fn, _Args&&... args) {
if (shutdown_.load(std::memory_order_acquire)) return false;
Expand All @@ -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 <typename _Fn, typename... _Args>
bool lfthreadpool::add_task_move(_Fn&& fn, _Args&&... args) {
if (shutdown_.load(std::memory_order_acquire)) return false;
Expand Down

0 comments on commit 59492ae

Please sign in to comment.