28 #include <condition_variable> 45 std::queue<std::function<void()>> m_queue;
50 std::vector<std::thread> m_threads;
60 std::condition_variable m_condition;
70 unsigned int m_numThreads;
90 template<
class T,
class... Args>
93 using pkgdTask = std::packaged_task<typename std::invoke_result<T, Args...>::type()>;
95 std::shared_ptr<pkgdTask> task = std::make_shared<pkgdTask>(std::bind(std::forward<T>(t), std::forward<Args>(args)...));
96 auto result = task->get_future();
99 m_queue.emplace([task]() { (*task)(); });
102 m_condition.notify_one();
110 unsigned int getNumOfThreads();
117 void threadFunction();
#define AUD_NAMESPACE_BEGIN
Opens the audaspace namespace aud.
Definition: Audaspace.h:116
auto enqueue(T &&t, Args &&... args)
Enqueues a new task for the threads to realize.
Definition: ThreadPool.h:91
#define AUD_API
Used for exporting symbols in the shared library.
Definition: Audaspace.h:93
This represents pool of threads.
Definition: ThreadPool.h:39
#define AUD_NAMESPACE_END
Closes the audaspace namespace aud.
Definition: Audaspace.h:119
The main header file of the library defining the namespace and basic data types.