Set TaskInfo to the ConcurrentFunction
Set TaskInfo to the ConcurrentFunction

Signed-off-by: huangfeijie <huangfeijie@huawei.com>
This commit is contained in:
huangfeijie 2024-11-20 21:12:10 +08:00
parent 924f7eaa9b
commit 389fad4bae
2 changed files with 10 additions and 0 deletions

View File

@ -790,6 +790,15 @@ void EcmaVM::TriggerConcurrentCallback(JSTaggedValue result, JSTaggedValue hint)
} }
void *taskInfo = reinterpret_cast<void*>(thread_->GetTaskInfo()); void *taskInfo = reinterpret_cast<void*>(thread_->GetTaskInfo());
if (UNLIKELY(taskInfo == nullptr)) {
JSTaggedValue extraInfoValue = functionInfo->GetFunctionExtraInfo();
if (!extraInfoValue.IsJSNativePointer()) {
LOG_ECMA(INFO) << "FunctionExtraInfo is not JSNativePointer";
return;
}
JSHandle<JSNativePointer> extraInfo(thread_, extraInfoValue);
taskInfo = extraInfo->GetData();
}
// clear the taskInfo when return, which can prevent the callback to get it // clear the taskInfo when return, which can prevent the callback to get it
thread_->SetTaskInfo(reinterpret_cast<uintptr_t>(nullptr)); thread_->SetTaskInfo(reinterpret_cast<uintptr_t>(nullptr));
auto localResultRef = JSNApiHelper::ToLocal<JSValueRef>(JSHandle<JSTaggedValue>(thread_, result)); auto localResultRef = JSNApiHelper::ToLocal<JSValueRef>(JSHandle<JSTaggedValue>(thread_, result));

View File

@ -4185,6 +4185,7 @@ bool JSNApi::InitForConcurrentFunction(EcmaVM *vm, Local<JSValueRef> function, v
LOG_ECMA(ERROR) << "Function is not concurrent"; LOG_ECMA(ERROR) << "Function is not concurrent";
return false; return false;
} }
JSFunction::SetFunctionExtraInfo(thread, transFunc, nullptr, nullptr, taskInfo);
transFunc->SetTaskConcurrentFuncFlag(1); // 1 : concurrent function flag transFunc->SetTaskConcurrentFuncFlag(1); // 1 : concurrent function flag
thread->SetTaskInfo(reinterpret_cast<uintptr_t>(taskInfo)); thread->SetTaskInfo(reinterpret_cast<uintptr_t>(taskInfo));
thread->SetIsInConcurrentScope(true); thread->SetIsInConcurrentScope(true);