diff --git a/adapter/uhdf2/hdi/BUILD.gn b/adapter/uhdf2/hdi/BUILD.gn index 43786376b418ce31edb95a51ec70f0a15c864b03..11bef242f5f8ae690bfe6c83442fb4c03d6f4bda 100644 --- a/adapter/uhdf2/hdi/BUILD.gn +++ b/adapter/uhdf2/hdi/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2023 Huawei Device Co., Ltd. +# Copyright (c) 2021-2025 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 @@ -61,8 +61,10 @@ if (defined(ohos_lite)) { } else { ohos_shared_library("libhdi") { branch_protector_ret = "pac_ret" + + defines = [ ] if (target_cpu == "arm64" || target_cpu == "x86_64") { - defines = [ "__ARCH64__" ] + defines += [ "__ARCH64__" ] } include_dirs = [ @@ -121,6 +123,13 @@ if (defined(ohos_lite)) { ] } + if (with_ffrt) { + external_deps += [ + "ffrt:libffrt" + ] + defines += [ "__FFRT__" ] + } + innerapi_tags = [ "chipsetsdk_sp", "platformsdk_indirect", diff --git a/adapter/uhdf2/hdi/src/hdi_support.cpp b/adapter/uhdf2/hdi/src/hdi_support.cpp index febe1f6198d243302245355530b1e4aec5ee5162..4e570238e6de89cbe83776f6402941a4942d1766 100644 --- a/adapter/uhdf2/hdi/src/hdi_support.cpp +++ b/adapter/uhdf2/hdi/src/hdi_support.cpp @@ -23,7 +23,7 @@ #include #include #include - +#include "hdi_mutex.h" #include "hdf_base.h" #include "hdf_core_log.h" @@ -93,7 +93,7 @@ struct HdiImpl { }; static std::map g_hdiConstructorMap; -static std::mutex g_loaderMutex; +static mutex_t g_loaderMutex; static int32_t ParseInterface( const std::string &desc, std::string &interface, std::string &libName, const char *serviceName) @@ -152,7 +152,7 @@ void *LoadHdiImpl(const char *desc, const char *serviceName) return nullptr; } - std::lock_guard lock(g_loaderMutex); + std::lock_guard lock(g_loaderMutex); auto constructor = g_hdiConstructorMap.find(libName); if (constructor != g_hdiConstructorMap.end()) { return constructor->second.constructor(); @@ -200,7 +200,7 @@ void UnloadHdiImpl(const char *desc, const char *serviceName, void *impl) HDF_LOGE("%{public}s: failed to parse hdi interface info from '%{public}s'", __func__, desc); return; } - std::lock_guard lock(g_loaderMutex); + std::lock_guard lock(g_loaderMutex); auto constructor = g_hdiConstructorMap.find(libName); if (constructor != g_hdiConstructorMap.end() && constructor->second.destructor != nullptr) { constructor->second.destructor(impl); diff --git a/adapter/uhdf2/hdi/src/idevmgr_client.cpp b/adapter/uhdf2/hdi/src/idevmgr_client.cpp index 8fe1caf986a5a31b8704dd56569aa37afad3bde0..c631ab98158b1610eb3310c819658a6cc3195e6c 100644 --- a/adapter/uhdf2/hdi/src/idevmgr_client.cpp +++ b/adapter/uhdf2/hdi/src/idevmgr_client.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 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 @@ -20,7 +20,7 @@ #include #include #include - +#include "hdi_mutex.h" #include "idevmgr_hdi.h" #include "iservmgr_hdi.h" @@ -32,7 +32,7 @@ namespace DeviceManager { namespace V1_0 { #define HDF_MAX_HOST_COUNT 0xFF -std::mutex g_remoteMutex; +mutex_t g_remoteMutex; enum DevmgrCmdId : uint32_t { DEVMGR_SERVICE_ATTACH_DEVICE_HOST = 1, @@ -71,7 +71,7 @@ int32_t DeviceManagerProxy::LoadDevice(const std::string &serviceName) return HDF_FAILURE; } - std::unique_lock lock(g_remoteMutex); + std::unique_lock lock(g_remoteMutex); if (Remote() == nullptr) { HDF_LOGE("invalid param Remote()"); return HDF_ERR_INVALID_PARAM; @@ -97,7 +97,7 @@ int32_t DeviceManagerProxy::UnloadDevice(const std::string &serviceName) return HDF_FAILURE; } - std::unique_lock lock(g_remoteMutex); + std::unique_lock lock(g_remoteMutex); if (Remote() == nullptr) { HDF_LOGE("invalid param Remote()"); return HDF_ERR_INVALID_PARAM; @@ -168,7 +168,7 @@ int32_t DeviceManagerProxy::ListAllDevice(std::vector &deviceInf } MessageOption option; - std::unique_lock lock(g_remoteMutex); + std::unique_lock lock(g_remoteMutex); if (Remote() == nullptr) { HDF_LOGE("invalid param Remote()"); return HDF_ERR_INVALID_PARAM; @@ -221,7 +221,7 @@ int32_t DeviceManagerProxy::ListAllHost(std::vector &pidList) } MessageOption option; - std::unique_lock lock(g_remoteMutex); + std::unique_lock lock(g_remoteMutex); if (Remote() == nullptr) { HDF_LOGE("invalid param Remote()"); return HDF_ERR_INVALID_PARAM; @@ -250,7 +250,7 @@ sptr IDeviceManager::Get() return nullptr; } - std::unique_lock lock(g_remoteMutex); + std::unique_lock lock(g_remoteMutex); sptr remote = servmgr->GetService("hdf_device_manager"); if (remote != nullptr) { return hdi_facecast(remote); diff --git a/adapter/uhdf2/hdi/src/iservmgr_client.cpp b/adapter/uhdf2/hdi/src/iservmgr_client.cpp index e8b3fdb95b6b23fb41e96b7eacf2d98e67018fe6..e855530603d93014d126574237f01e78e921b45e 100644 --- a/adapter/uhdf2/hdi/src/iservmgr_client.cpp +++ b/adapter/uhdf2/hdi/src/iservmgr_client.cpp @@ -22,7 +22,7 @@ #include #include #include - +#include "hdi_mutex.h" #include "hdf_device_manager_interface_code.h" #include "iservmgr_hdi.h" @@ -35,7 +35,7 @@ namespace HDI { namespace ServiceManager { namespace V1_0 { constexpr int DEVICE_SERVICE_MANAGER_SA_ID = 5100; -std::mutex g_remoteMutex; +mutex_t g_remoteMutex; class ServiceManagerProxy : public IProxyBroker { public: @@ -60,7 +60,7 @@ sptr IServiceManager::Get() return nullptr; } - std::unique_lock lock(g_remoteMutex); + std::lock_guard lock(g_remoteMutex); sptr remote = saManager->GetSystemAbility(DEVICE_SERVICE_MANAGER_SA_ID); if (remote != nullptr) { return new ServiceManagerProxy(remote); @@ -82,7 +82,7 @@ int32_t ServiceManagerProxy::RegisterServiceStatusListener( return HDF_FAILURE; } - std::unique_lock lock(g_remoteMutex); + std::unique_lock lock(g_remoteMutex); if (Remote() == nullptr) { HDF_LOGE("invalid param Remote()"); return HDF_ERR_INVALID_PARAM; @@ -106,7 +106,7 @@ int32_t ServiceManagerProxy::UnregisterServiceStatusListener(::OHOS::sptr lock(g_remoteMutex); + std::unique_lock lock(g_remoteMutex); if (Remote() == nullptr) { HDF_LOGE("invalid param Remote()"); return HDF_ERR_INVALID_PARAM; @@ -135,7 +135,7 @@ sptr ServiceManagerProxy::GetService(const char *serviceName) } MessageOption option; - std::unique_lock lock(g_remoteMutex); + std::unique_lock lock(g_remoteMutex); if (Remote() == nullptr) { HDF_LOGE("invalid param Remote()"); return nullptr; @@ -176,7 +176,7 @@ int32_t ServiceManagerProxy::ListAllService(std::vector &service } MessageOption option; - std::unique_lock lock(g_remoteMutex); + std::unique_lock lock(g_remoteMutex); if (Remote() == nullptr) { HDF_LOGE("invalid param Remote()"); return HDF_ERR_INVALID_PARAM; @@ -208,7 +208,7 @@ int32_t ServiceManagerProxy::ListServiceByInterfaceDesc( } MessageOption option; - std::unique_lock lock(g_remoteMutex); + std::unique_lock lock(g_remoteMutex); if (Remote() == nullptr) { HDF_LOGE("invalid param Remote()"); return HDF_ERR_INVALID_PARAM; diff --git a/adapter/uhdf2/hdi/src/stub_collector.cpp b/adapter/uhdf2/hdi/src/stub_collector.cpp index cee5af8e9c24e3a2c513de62c3760dbee18ea854..e51f0053b103bba8d97dd20a744c4a6efb008505 100644 --- a/adapter/uhdf2/hdi/src/stub_collector.cpp +++ b/adapter/uhdf2/hdi/src/stub_collector.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -17,11 +17,12 @@ #include #include #include +#include "hdi_mutex.h" static std::map g_constructorMap; static std::map g_stubMap; -static std::mutex g_consMapLock; -static std::mutex g_stubMapLock; +static mutex_t g_consMapLock; +static mutex_t g_stubMapLock; void StubConstructorRegister(const char *ifDesc, struct StubConstructor *constructor) { @@ -29,7 +30,7 @@ void StubConstructorRegister(const char *ifDesc, struct StubConstructor *constru return; } - const std::lock_guard lock(g_consMapLock); + const std::lock_guard lock(g_consMapLock); if (g_constructorMap.find(ifDesc) != g_constructorMap.end()) { HDF_LOGE("repeat registration stub constructor for if %{public}s", ifDesc); return; @@ -44,7 +45,7 @@ void StubConstructorUnregister(const char *ifDesc, const struct StubConstructor return; } - const std::lock_guard lock(g_consMapLock); + const std::lock_guard lock(g_consMapLock); g_constructorMap.erase(ifDesc); return; } @@ -54,14 +55,14 @@ struct HdfRemoteService **StubCollectorGetOrNewObject(const char *ifDesc, void * if (ifDesc == nullptr || servPtr == nullptr) { return nullptr; } - const std::lock_guard stublock(g_stubMapLock); + const std::lock_guard stublock(g_stubMapLock); auto stub = g_stubMap.find(servPtr); if (stub != g_stubMap.end()) { return stub->second; } HDF_LOGI("g_constructorMap size %{public}zu", g_constructorMap.size()); - const std::lock_guard lock(g_consMapLock); + const std::lock_guard lock(g_consMapLock); for (auto &consruct : g_constructorMap) { HDF_LOGI("g_constructorMap it: %{public}s", consruct.first.c_str()); } @@ -92,12 +93,12 @@ void StubCollectorRemoveObject(const char *ifDesc, void *servPtr) return; } - const std::lock_guard stublock(g_stubMapLock); + const std::lock_guard stublock(g_stubMapLock); auto stub = g_stubMap.find(servPtr); if (stub == g_stubMap.end()) { return; } - const std::lock_guard lock(g_consMapLock); + const std::lock_guard lock(g_consMapLock); auto constructor = g_constructorMap.find(ifDesc); if (constructor == g_constructorMap.end()) { HDF_LOGE("no stub constructor for %{public}s", ifDesc); diff --git a/adapter/uhdf2/uhdf.gni b/adapter/uhdf2/uhdf.gni index 9de2161f44a1fef9aa480f1ce0f8a2e7e67d9bc3..5bdbde19ed4d1df45c6b54b8df3f5a6172fd8609 100644 --- a/adapter/uhdf2/uhdf.gni +++ b/adapter/uhdf2/uhdf.gni @@ -26,4 +26,9 @@ declare_args() { with_sample = false hdf_core_default_peripheral_config = true + + with_ffrt = false + if (defined(global_parts_info) && defined(global_parts_info.resourceschedule_ffrt)) { + with_ffrt = true + } } diff --git a/bundle.json b/bundle.json index 7b2f6d0ce1cabcaf013c57a0a3ac8dbbbc6e492e..32835a25e831ddda9876d0036cf60b3f92c057f4 100644 --- a/bundle.json +++ b/bundle.json @@ -31,7 +31,8 @@ "samgr", "selinux_adapter", "hilog_lite", - "hicollie" + "hicollie", + "ffrt" ], "third_party": [ "bounds_checking_function" diff --git a/interfaces/inner_api/hdi/base/hdi_mutex.h b/interfaces/inner_api/hdi/base/hdi_mutex.h new file mode 100644 index 0000000000000000000000000000000000000000..3a75b281d64a32d84bdc39e009427da5dc55c3ec --- /dev/null +++ b/interfaces/inner_api/hdi/base/hdi_mutex.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 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 HDI_MUTEX_H +#define HDI_MUTEX_H + +#ifdef __FFRT__ +#include "ffrt.h" +typedef ffrt::mutex mutex_t; +#else +#include +typedef std::mutex mutex_t; +#endif + +#endif /* HDI_MUTEX_H */