!1025 修复ipc循环依赖问题

Merge pull request !1025 from zhuguoyang/master
This commit is contained in:
openharmony_ci 2024-04-13 15:35:02 +00:00 committed by Gitee
commit 7fb33f0ef0
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
7 changed files with 86 additions and 13 deletions

View File

@ -81,7 +81,6 @@ ohos_shared_library("ipc_core") {
"access_token:libaccesstoken_sdk",
"c_utils:utils",
"dsoftbus:softbus_client",
"ffrt:libffrt",
"hilog:libhilog",
"hisysevent:libhisysevent",
"hitrace:libhitracechain",

View File

@ -66,7 +66,6 @@ ohos_shared_library("ipc_single") {
external_deps = [
"c_utils:utils",
"ffrt:libffrt",
"hilog:libhilog",
"hisysevent:libhisysevent",
"hitrace:libhitracechain",

View File

@ -56,7 +56,6 @@ using namespace IPC_SINGLE;
handle, error, (desc).c_str())
static constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_ID_IPC_PROXY, "IPCObjectProxy" };
static constexpr uint32_t IPC_OBJECT_MASK = 0xffffff;
static constexpr int PRINT_ERR_CNT = 100;
IPCObjectProxy::IPCObjectProxy(int handle, std::u16string descriptor, int proto)

View File

@ -60,7 +60,6 @@ static constexpr int SHELL_UID = 2000;
static constexpr int HIDUMPER_SERVICE_UID = 1212;
static constexpr int COEFF_MILLI_TO_MICRO = 1000;
static constexpr int IPC_CMD_PROCESS_WARN_TIME = 500 * COEFF_MILLI_TO_MICRO; // 500 ms
static constexpr uint32_t IPC_OBJECT_MASK = 0xffffff;
IPCObjectStub::IPCObjectStub(std::u16string descriptor, bool serialInvokeFlag)
: IRemoteObject(descriptor), serialInvokeFlag_(serialInvokeFlag), lastRequestTime_(0)

View File

@ -29,7 +29,7 @@
#include "string"
#include "unistd.h"
#ifdef FFRT_IPC_ENABLE
#include "c/ffrt_ipc.h"
#include "ffrtadapter.h"
#endif
namespace OHOS {
@ -203,14 +203,18 @@ int IPCSkeleton::FlushCommands(IRemoteObject *object)
#ifdef FFRT_IPC_ENABLE
IPCObjectProxy *proxy = reinterpret_cast<IPCObjectProxy *>(object);
bool isBinderInvoker = (proxy->GetProto() == IRemoteObject::IF_PROT_BINDER);
auto ffrtTaskSetLegacyMode = FFRTAdapter::Instance()->FfrtTaskSetLegacyMode;
if (ffrtTaskSetLegacyMode == nullptr) {
return IPC_SKELETON_NULL_OBJECT_ERR;
}
if (isBinderInvoker) {
ffrt_this_task_set_legacy_mode(true);
ffrtTaskSetLegacyMode(true);
}
#endif
int ret = invoker->FlushCommands(object);
#ifdef FFRT_IPC_ENABLE
if (isBinderInvoker) {
ffrt_this_task_set_legacy_mode(false);
ffrtTaskSetLegacyMode(false);
}
#endif
return ret;

View File

@ -30,7 +30,7 @@
#include "string_ex.h"
#include "sys_binder.h"
#ifdef FFRT_IPC_ENABLE
#include "c/ffrt_ipc.h"
#include "ffrtadapter.h"
#endif
#if defined(__arm__) || defined(__aarch64__)
@ -151,8 +151,6 @@ int BinderInvoker::SendRequest(int handle, uint32_t code, MessageParcel &data, M
// set client send trace point if trace is enabled
HiTraceId childId = HitraceInvoker::TraceClientSend(handle, code, newData, flags, traceId);
ThreadMigrationDisabler _d;
if (!TranslateDBinderProxy(handle, data)) {
return IPC_INVOKER_WRITE_TRANS_ERR;
}
@ -166,11 +164,15 @@ int BinderInvoker::SendRequest(int handle, uint32_t code, MessageParcel &data, M
error = WaitForCompletion(nullptr);
} else {
#ifdef FFRT_IPC_ENABLE
ffrt_this_task_set_legacy_mode(true);
auto ffrtTaskSetLegacyMode = FFRTAdapter::Instance()->FfrtTaskSetLegacyMode;
if (ffrtTaskSetLegacyMode == nullptr) {
return IPC_INVOKER_ERR;
}
ffrtTaskSetLegacyMode(true);
#endif
error = WaitForCompletion(&reply);
#ifdef FFRT_IPC_ENABLE
ffrt_this_task_set_legacy_mode(false);
ffrtTaskSetLegacyMode(false);
#endif
}
HitraceInvoker::TraceClientReceieve(handle, code, flags, traceId, childId);
@ -820,7 +822,6 @@ int BinderInvoker::HandleCommands(uint32_t cmd)
void BinderInvoker::JoinThread(bool initiative)
{
ThreadMigrationDisabler _d;
isMainWorkThread = initiative;
output_.WriteUint32(initiative ? BC_ENTER_LOOPER : BC_REGISTER_LOOPER);
StartWorkLoop();

View File

@ -0,0 +1,72 @@
/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_IPC_UTIL_FFRTADAPTER_H
#define OHOS_IPC_UTIL_FFRTADAPTER_H
#include <dlfcn.h>
#include <string>
#include "log_tags.h"
#include "ipc_debug.h"
namespace OHOS {
static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, LOG_ID_IPC_BASE, "ipc_ffrt_object" };
void ffrt_this_task_set_legacy_mode(bool mode);
using FfrtTaskSetLegacyModeType = decltype(ffrt_this_task_set_legacy_mode)*;
#ifdef __aarch64__
static const std::string FFRT_LIB_PATH = "/system/lib64/chipset-sdk/libffrt.so";
#else
static const std::string FFRT_LIB_PATH = "/system/lib/chipset-sdk/libffrt.so";
#endif
class FFRTAdapter {
public:
FFRTAdapter()
{
Load();
}
~FFRTAdapter()
{
}
static FFRTAdapter* Instance()
{
static FFRTAdapter instance;
return &instance;
}
FfrtTaskSetLegacyModeType FfrtTaskSetLegacyMode = nullptr;
private:
void Load()
{
if (handle != nullptr) {
return;
}
handle = dlopen(FFRT_LIB_PATH.c_str(), RTLD_NOW | RTLD_LOCAL);
if (handle == nullptr) {
ZLOGE(LOG_LABEL, "ffrt lib handle is null.");
return;
}
FfrtTaskSetLegacyMode = reinterpret_cast<FfrtTaskSetLegacyModeType>(
dlsym(handle, "ffrt_this_task_set_legacy_mode"));
if (FfrtTaskSetLegacyMode == nullptr) {
ZLOGE(LOG_LABEL, "get ffrt_this_task_set_legacy_mode symbol fail.");
return;
}
}
void* handle = nullptr;
};
} // namespace OHOS
#endif // OHOS_IPC_UTIL_FFRTADAPTER_H