1#ifndef LIBFILEZILLA_THREAD_POOL_HEADER
2#define LIBFILEZILLA_THREAD_POOL_HEADER
24class FZ_PUBLIC_SYMBOL async_task final {
26 async_task() =
default;
31 async_task(async_task
const&) =
delete;
32 async_task& operator=(async_task
const&) =
delete;
34 async_task(async_task && other)
noexcept;
35 async_task& operator=(async_task && other)
noexcept;
41 explicit operator bool()
const {
return impl_ !=
nullptr; }
47 friend class thread_pool;
49 async_task_impl* impl_{};
53class pooled_thread_impl;
63class FZ_PUBLIC_SYMBOL thread_pool final
69 thread_pool(thread_pool
const&) =
delete;
70 thread_pool& operator=(thread_pool
const&) =
delete;
73 async_task
spawn(std::function<
void()>
const& f);
74 async_task
spawn(std::function<
void()> && f);
77 FZ_PRIVATE_SYMBOL pooled_thread_impl* get_or_create_thread();
79 friend class async_task;
80 friend class pooled_thread_impl;
82 std::vector<pooled_thread_impl*> threads_;
83 std::vector<pooled_thread_impl*> idle_;
void join()
Wait for the task to finish, adds the now idle thread back into the pool.
void detach()
Detach the running thread from the task. Once done, the thread adds itself back into the pool.
~async_task()
If task has not been detached, calls join.
Lean replacement for std::(recursive_)mutex.
Definition mutex.hpp:57
A dumb thread-pool for asynchronous tasks.
Definition thread_pool.hpp:64
async_task spawn(std::function< void()> const &f)
Spawns a new asynchronous task.
Sets some global macros and further includes string.hpp.
Thread synchronization primitives: mutex, scoped_lock and condition.
The namespace used by libfilezilla.
Definition apply.hpp:17