Submit a task to task queue, and wait for a idle thread to execute it.
pack function pointer with packaged_task and get future.
pack task as a lambda and submit it to queue.
Expand threads container if in MODE_CACHED.
704 {
706
707 using RType = decltype(func(args...));
708
712 auto task = std::make_shared<std::packaged_task<RType()>>(std::bind(std::forward<Func>(func), std::forward<Args>(args)...));
713 std::future<RType> result =
task->get_future();
714
715 {
716 std::unique_lock<std::mutex> lock(
m_Mutex);
717
723
728 {
730 {
732 {
734 uint32_t threadId = ptr->GetId();
735
736 ptr->Start();
737 m_Threads.emplace(threadId, std::move(ptr));
738
741
742 break;
743 }
744 }
745 }
746 }
747
749
750 return result;
751 }
#define SPICES_PROFILE_ZONE
std::atomic_int m_IdleThreadSize
Idled thread size.
std::queue< Task > m_TaskQueue
Task Queue.
std::atomic_int m_Tasks
Number of tasks;.
PoolMode m_PoolMode
Thread Pool Run Mode.
std::mutex m_Mutex
Mutex for thread safe.
std::unordered_map< uint32_t, std::unique_ptr< Thread< Params... > > > m_Threads
Threads Container.
std::condition_variable m_NotEmpty
Task Queue not empty.
void ThreadFunc(Thread<> *thread)
Thread Function.
std::atomic_int m_NThreads
Threads Count.
const uint32_t THREAD_MAX_THRESHHOLD