Name thread.
Exit.
Try recovery unused threads.
Rink Second, Pool Tasks.
execute task.
Name thread.
Exit.
Try recovery unused threads.
Rink Second, Pool Tasks.
execute task.
70 {
72
76 std::stringstream ss;
78
80
81 auto lastTime = std::chrono::high_resolution_clock::now();
82
83 for (;;)
84 {
86 {
87 std::unique_lock<std::mutex> lock(
m_Mutex);
88
90 {
95 {
99 return;
100 }
101
103 {
104 if (
m_NotEmpty.wait_for(lock, std::chrono::seconds(1)) == std::cv_status::timeout)
105 {
106 auto now = std::chrono::high_resolution_clock::now();
107 auto dur = std::chrono::duration_cast<std::chrono::seconds>(now - lastTime);
108
113 {
117 return;
118 }
119 }
120 }
121 else
122 {
124 }
125 }
126
130 task = thread->RequireTask();
131
136 {
139 thread->SetThreadInTask(true);
141 }
142
144 }
145
147 {
149 }
150
155 {
158 thread->SetThreadInTask(false);
161 }
162 else
163 {
164 thread->SetThreadInTask(false);
167 }
168
169 lastTime = std::chrono::high_resolution_clock::now();
170 }
171 }
#define SPICES_PROFILE_ZONE
static bool SetThreadName(const std::string &name)
Set Thread name.
bool m_IsSuspend
True if needs suspend on executing the task.
std::atomic_int m_IdleThreadSize
Idled thread size.
std::queue< Task > m_TaskQueue
Task Queue.
std::atomic_int m_Tasks
Number of tasks;.
std::condition_variable m_ExitCond
Thread pool Exit Condition.
PoolMode m_PoolMode
Thread Pool Run Mode.
std::function< void(Params...)> Task
Thread Function lambda Object.
std::mutex m_Mutex
Mutex for thread safe.
std::unordered_map< uint32_t, std::unique_ptr< Thread< Params... > > > m_Threads
Threads Container.
std::string m_PoolName
This ThreadPool Name.
std::condition_variable m_NotEmpty
Task Queue not empty.
uint32_t m_InitThreadSize
Initialized thread size.
uint32_t m_ThreadIdleTimeOut
thread idle time out.
std::atomic_int m_NThreads
Threads Count.
std::condition_variable m_IdleCond
Thread pool thread idle Condition.
std::atomic_bool m_IsPoolRunning
True if this thread pool is in use.
VkCommandBuffer CreateParallelCommandBuffers(uint32_t threadId)
Create second CommandBuffer in rhi threadPool thread.