Signed-off-by: htt1997 <hutao105@huawei.com>
This commit is contained in:
htt1997 2024-08-15 11:34:38 +08:00
parent 8f10a8d23c
commit 51c883cdd1
2 changed files with 13 additions and 4 deletions

View File

@ -26,7 +26,7 @@
namespace OHOS {
namespace MiscServices {
#define ASYNC_POST(env, ctx) asyncCall.Post(env, ctx, taskQueue_, __FUNCTION__)
#define ASYNC_POST(env, ctx) asyncCall.Post((env), (ctx), taskQueue_, __FUNCTION__)
using namespace std::chrono;
thread_local napi_ref JsTextInputClientEngine::TICRef_ = nullptr;
const std::string JsTextInputClientEngine::TIC_CLASS_NAME = "TextInputClient";

View File

@ -24,7 +24,7 @@ namespace OHOS {
namespace MiscServices {
using namespace std::chrono;
constexpr size_t ARGC_MAX = 6;
constexpr int32_t MAX_WAIT_TIME = 100;
constexpr int32_t MAX_WAIT_TIME = 500; // ms
static inline uint64_t GetTimeStamp()
{
return duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
@ -142,6 +142,10 @@ napi_value AsyncCall::SyncCall(napi_env env, AsyncCall::Context::ExecAction exec
void AsyncCall::OnExecute(napi_env env, void *data)
{
AsyncContext *context = reinterpret_cast<AsyncContext *>(data);
if (context == nullptr || context->ctx == nullptr) {
IMSA_HILOGE("context or context->ctx is nullptr!");
return;
}
context->ctx->Exec();
}
@ -149,10 +153,11 @@ void AsyncCall::OnExecuteSeq(napi_env env, void *data)
{
OnExecute(env, data);
AsyncContext *context = reinterpret_cast<AsyncContext *>(data);
auto queue = context->queue;
if (queue == nullptr) {
if (context == nullptr || context->queue == nullptr) {
IMSA_HILOGE("context or context->queue is nullptr!");
return;
}
auto queue = context->queue;
std::unique_lock<ffrt::mutex> lock(queue->queuesMutex_);
if (!queue->taskQueue_.empty()) {
queue->taskQueue_.pop();
@ -166,6 +171,10 @@ void AsyncCall::OnComplete(napi_env env, napi_status status, void *data)
{
AsyncContext *context = reinterpret_cast<AsyncContext *>(data);
napi_value output = nullptr;
if (context == nullptr || context->ctx == nullptr) {
IMSA_HILOGE("context or context->ctx is nullptr!");
return;
}
napi_status runStatus = (*context->ctx)(env, &output);
napi_value result[ARG_BUTT] = { 0 };
if (status == napi_ok && runStatus == napi_ok) {