Submit a part commands task to task queue, and wait for a idle thread to execute it.
pack task as a lambda and submit it to queue.
Expand threads container if in MODE_CACHED.
89 {
91
92 using RType = decltype(func(nullptr, args...));
93
94 auto task = std::make_shared<std::packaged_task<RType(VkCommandBuffer)>>(std::bind(std::forward<Func>(func), std::placeholders::_1, std::forward<Args>(args)...));
95 std::future<decltype(func(nullptr, std::forward<Args>(args)...))> result =
task->get_future();
96
97 {
98 std::unique_lock<std::mutex> lock(
m_Mutex);
99
103 m_TaskQueue.emplace([
task](VkCommandBuffer cmdBuffer) { (*task)(cmdBuffer); });
105
110 {
112 {
114 {
116 uint32_t threadId = ptr->GetId();
117
118 ptr->Start();
119 m_Threads.emplace(threadId, std::move(ptr));
120
123
124 break;
125 }
126 }
127 }
128 }
129
131
132 return result;
133 }
#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.
std::atomic_int m_NThreads
Threads Count.
void ThreadFunc(Thread< VkCommandBuffer > *thread)
Thread Function.
const uint32_t THREAD_MAX_THRESHHOLD