MCPcopy Create free account
hub / github.com/cocos/cocos-engine / pushTask

Method pushTask

native/cocos/base/ThreadPool.cpp:211–245  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

209}
210
211void LegacyThreadPool::pushTask(const std::function<void(int)> &runnable,
212 TaskType type /* = DEFAULT*/) {
213 if (!_isFixedSize) {
214 _idleThreadNumMutex.lock();
215 int idleNum = _idleThreadNum;
216 _idleThreadNumMutex.unlock();
217
218 if (idleNum > _minThreadNum) {
219 if (_taskQueue.empty()) {
220 auto now = std::chrono::high_resolution_clock::now();
221 float seconds = TIME_MINUS(now, _lastShrinkTime);
222 if (seconds > _shrinkInterval) {
223 tryShrinkPool();
224 _lastShrinkTime = now;
225 }
226 }
227 } else if (idleNum == 0) {
228 stretchPool(_stretchStep);
229 }
230 }
231
232 auto callback = ccnew std::function<void(int)>([runnable](int tid) {
233 runnable(tid);
234 });
235
236 Task task;
237 task.type = type;
238 task.callback = callback;
239 _taskQueue.push(task);
240
241 {
242 std::unique_lock<std::mutex> lock(_mutex);
243 _cv.notify_one();
244 }
245}
246
247void LegacyThreadPool::stopAllTasks() {
248 Task task;

Callers 6

sendImmediateMethod · 0.80
sendImmediateMethod · 0.80
preloadEffectMethod · 0.80
jsb_global_load_imageFunction · 0.80
js_saveImageDataFunction · 0.80
initializeMethod · 0.80

Calls 4

nowFunction · 0.85
lockMethod · 0.80
emptyMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected