Lines Matching refs:worker

16 #include "worker.h"

34 Worker::PriorityScope::PriorityScope(Worker* worker, Priority taskPriority) : worker_(worker)
36 if (taskPriority != worker->priority_) {
37 HILOG_DEBUG("taskpool:: reset worker priority to match task priority");
47 worker->priority_ = taskPriority;
64 Worker* worker = new Worker(env);
65 worker->StartExecuteInThread();
66 return worker;
86 auto worker = static_cast<Worker*>(req->data);
87 HILOG_DEBUG("taskpool:: enter the worker loop and try to release thread: %{public}d", worker->tid_);
88 if (!worker->CheckFreeConditions()) {
92 TaskManager::GetInstance().RemoveWorker(worker);
96 // when there is no active handle, worker loop will stop automatically.
97 worker->CloseHandles();
99 uv_loop_t* loop = worker->GetWorkerLoop();
108 // only when all conditions are met can the worker be freed
110 HILOG_DEBUG("taskpool:: async callbacks may exist, the worker thread will not exit");
112 HILOG_DEBUG("taskpool:: listening operation exists, the worker thread will not exit");
114 HILOG_DEBUG("taskpool:: timer exists, the worker thread will not exit");
116 HILOG_DEBUG("taskpool:: waiting request exists, the worker thread will not exit");
118 HILOG_DEBUG("taskpool:: sub env exists, the worker thread will not exit");
120 HILOG_DEBUG("taskpool:: pending job exists, the worker thread will not exit");
122 HILOG_DEBUG("taskpool:: the worker thread will not exit during profiling");
126 HILOG_DEBUG("taskpool:: the worker %{public}d can't be released due to not meeting the conditions", tid_);
148 Worker* worker = reinterpret_cast<Worker*>(req->data);
149 if (worker == nullptr) {
150 HILOG_ERROR("taskpool:: worker is null");
153 worker->debuggerMutex_.lock();
154 auto task = std::move(worker->debuggerQueue_.front());
155 worker->debuggerQueue_.pop();
156 worker->debuggerMutex_.unlock();
197 HILOG_ERROR("taskpool:: worker loop is nullptr when init loop handle num.");
207 HILOG_ERROR("taskpool:: worker loop is nullptr when judge loop alive.");
221 auto worker = reinterpret_cast<Worker*>(const_cast<void*>(data));
223 napi_create_runtime(worker->hostEnv_, &worker->workerEnv_);
224 if (worker->workerEnv_ == nullptr) {
225 HILOG_ERROR("taskpool:: worker create runtime failed");
228 auto workerEngine = reinterpret_cast<NativeEngine*>(worker->workerEnv_);
229 // mark worker env is taskpoolThread
231 workerEngine->InitTaskPoolThread(worker->workerEnv_, Worker::TaskResultCallback);
233 uv_loop_t* loop = worker->GetWorkerLoop();
238 // save the worker tid
239 worker->tid_ = GetThreadId();
241 // Init worker task execute signal
242 ConcurrentHelper::UvHandleInit(loop, worker->performTaskSignal_, Worker::PerformTask, worker);
243 ConcurrentHelper::UvHandleInit(loop, worker->clearWorkerSignal_, Worker::ReleaseWorkerHandles, worker);
244 ConcurrentHelper::UvHandleInit(loop, worker->triggerGCCheckSignal_, Worker::TriggerGCCheck, worker);
249 ConcurrentHelper::UvHandleInit(loop, worker->debuggerOnPostTaskSignal_, Worker::HandleDebuggerTask, worker);
251 if (worker->PrepareForWorkerInstance()) {
253 worker->NotifyWorkerCreated();
255 worker->InitFfrtInfo();
256 worker->InitLoopHandleNum();
258 worker->RunLoop();
262 TaskManager::GetInstance().RemoveWorker(worker);
264 worker->ReleaseWorkerThreadContent();
265 delete worker;
266 worker = nullptr;
285 // Check exception after worker construction
313 // 2. delete NativeEngine created in worker thread
315 HILOG_ERROR("worker:: CallOffWorkerFunc error");
350 auto worker = reinterpret_cast<Worker*>(req->data);
351 auto workerEngine = reinterpret_cast<NativeEngine*>(worker->workerEnv_);
368 // the worker state is still RUNNING and the start time will be updated
384 auto worker = static_cast<Worker*>(req->data);
385 napi_env env = worker->workerEnv_;
386 TaskManager::GetInstance().NotifyWorkerRunning(worker);
389 worker->NotifyIdle();
392 RunningScope runningScope(worker);
393 PriorityScope priorityScope(worker, taskInfo.second);
404 worker->NotifyTaskBegin();
406 if (!task->UpdateTask(startTime, worker)) {
407 worker->NotifyTaskFinished();
414 worker->UpdateLongTaskInfo(task);
416 worker->StoreTaskId(task->taskId_);
428 worker->NotifyTaskResult(env, task, errorInfo);
432 if (!worker->InitTaskPoolFunc(env, func, task)) {
435 worker->hasExecuted_ = true;
453 worker->UpdateExecutedInfo();
484 Worker* worker = reinterpret_cast<Worker*>(task->worker_);
485 if (worker != nullptr) {
486 std::lock_guard<std::mutex> lock(worker->currentTaskIdMutex_);
487 auto iter = std::find(worker->currentTaskId_.begin(), worker->currentTaskId_.end(), task->taskId_);
488 if (iter != worker->currentTaskId_.end()) {
489 worker->currentTaskId_.erase(iter);
492 HILOG_FATAL("taskpool:: worker is nullptr");
495 if (!task->VerifyAndPostResult(worker->priority_)) {
500 worker->NotifyTaskFinished();
520 auto worker = static_cast<Worker*>(task->worker_);
521 worker->isExecutingLongTask_ = task->IsLongTask();
582 // if the worker is blocked, just skip
589 // Only when the worker has no longTask can it be released.