37 : m_queue_shutdown(false)
38 , m_num_threads(num_threads)
40 , m_threads_running(0)
67 lock_queue_mutex.unlock();
71 Logging::trace(
nullptr,
"Starting job taking pool thread no. %1 with id 0x%<" FFMPEGFS_FORMAT_PTHREAD_T
">2.", thread_no, pthread_self());
78 Logging::trace(
nullptr,
"The job using pool thread no. %1 with id 0x%<" FFMPEGFS_FORMAT_PTHREAD_T
">2 has exited with return code %3.", thread_no, pthread_self(), ret);
static void warning(const T filename, const std::string &format_string, Args &&...args)
Write warning level log entry.
static void debug(const T filename, const std::string &format_string, Args &&...args)
Write debug level log entry.
static void trace(const T filename, const std::string &format_string, Args &&...args)
Write trace level log entry.
static void info(const T filename, const std::string &format_string, Args &&...args)
Write info level log entry.
int init(unsigned int num_threads=0)
Initialise thread pool. Initialise the thread pool. Does nothing if called more than once.
std::condition_variable m_queue_cond
unsigned int pool_size() const
Get current pool size.
unsigned int m_num_threads
std::function< int(void)> FunctionPointer
Pointer to thread pool function.
void loop_function()
Start loop function.
std::vector< std::thread > m_thread_pool
std::queue< FunctionPointer > m_thread_queue
static void loop_function_starter(thread_pool &tp)
Start loop function.
void tear_down(bool silent=false)
Shut down the thread pool.
unsigned int m_cur_threads
bool schedule_thread(FunctionPointer &&func)
Schedule a new thread from pool.
virtual ~thread_pool()
Object destructor. Ends all threads and cleans up resources.
std::atomic_uint32_t m_threads_running
unsigned int current_queued()
Get number of currently queued threads.
thread_pool(unsigned int num_threads=std::thread::hardware_concurrency() *4)
Construct a thread_pool object.
std::atomic_bool m_queue_shutdown
unsigned int current_running() const
Get number of currently running threads.
std::unique_ptr< thread_pool > tp
Thread pool object.
Provide various log facilities to stderr, disk or syslog.
Thread pool class implementation.