From e2cb51f3faf30d8eefc4887c71ffe055d1b21cdd Mon Sep 17 00:00:00 2001 From: "cheng.wang_c" Date: Thu, 6 Apr 2023 10:10:53 +0800 Subject: [PATCH] IssueNo:merge thread Description: : merge thread Sig:SIG_Telephony Feature or Bugfix: Feature Binary Source: No Signed-off-by: cheng.wang_c Change-Id: I045a9802ca305fe1a32fbf854e464b3cc3850dbf --- BUILD.gn | 1 + services/include/runner_pool.h | 42 ++++++++++++++++++ services/src/cellular_data_handler.cpp | 4 +- services/src/cellular_data_service.cpp | 5 ++- services/src/runner_pool.cpp | 59 ++++++++++++++++++++++++++ 5 files changed, 107 insertions(+), 4 deletions(-) create mode 100755 services/include/runner_pool.h create mode 100644 services/src/runner_pool.cpp diff --git a/BUILD.gn b/BUILD.gn index 0d635561..45ebaa59 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -32,6 +32,7 @@ ohos_shared_library("tel_cellular_data") { "$SOURCE_DIR/services/src/data_connection_manager.cpp", "$SOURCE_DIR/services/src/data_connection_monitor.cpp", "$SOURCE_DIR/services/src/data_switch_settings.cpp", + "$SOURCE_DIR/services/src/runner_pool.cpp", "$SOURCE_DIR/services/src/sim_account_callback_proxy.cpp", "$SOURCE_DIR/services/src/state_machine/activating.cpp", "$SOURCE_DIR/services/src/state_machine/active.cpp", diff --git a/services/include/runner_pool.h b/services/include/runner_pool.h new file mode 100755 index 00000000..eec28b58 --- /dev/null +++ b/services/include/runner_pool.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2023 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 RUNNER_POOL_H +#define RUNNER_POOL_H + +#include +#include "event_runner.h" + +namespace OHOS { +namespace Telephony { +class RunnerPool { +public: + static RunnerPool &GetInstance(); + void Init(); + std::shared_ptr GetCommonRunner(); + +private: + std::shared_ptr CreateRunner(const std::string name); + RunnerPool() = default; + ~RunnerPool() = default; + +private: + std::shared_ptr commonRunner_ = nullptr; + static RunnerPool runnerPool_; + bool isInit_ = false; +}; +} // namespace Telephony +} // namespace OHOS +#endif // RUNNER_POOL_H diff --git a/services/src/cellular_data_handler.cpp b/services/src/cellular_data_handler.cpp index 6dab123d..98fb4174 100644 --- a/services/src/cellular_data_handler.cpp +++ b/services/src/cellular_data_handler.cpp @@ -28,6 +28,7 @@ #include "hril_call_parcel.h" #include "net_specifier.h" #include "radio_event.h" +#include "runner_pool.h" #include "str_convert.h" #include "string_ex.h" #include "telephony_log_wrapper.h" @@ -546,12 +547,11 @@ std::shared_ptr CellularDataHandler::FindIdleCellularD std::shared_ptr CellularDataHandler::CreateCellularDataConnect() { if (stateMachineEventLoop_ == nullptr) { - stateMachineEventLoop_ = AppExecFwk::EventRunner::Create("CellularDataStateMachine"); + stateMachineEventLoop_ = RunnerPool::GetInstance().GetCommonRunner(); if (stateMachineEventLoop_ == nullptr) { TELEPHONY_LOGE("Slot%{public}d: failed to create EventRunner", slotId_); return nullptr; } - stateMachineEventLoop_->Run(); } std::shared_ptr cellularDataStateMachine = std::make_shared(connectionManager_, shared_from_this(), stateMachineEventLoop_); diff --git a/services/src/cellular_data_service.cpp b/services/src/cellular_data_service.cpp index a7f4f1ad..94e69829 100644 --- a/services/src/cellular_data_service.cpp +++ b/services/src/cellular_data_service.cpp @@ -22,6 +22,7 @@ #include "core_manager_inner.h" #include "data_connection_monitor.h" #include "net_specifier.h" +#include "runner_pool.h" #include "string_ex.h" #include "system_ability_definition.h" #include "telephony_common_utils.h" @@ -49,6 +50,7 @@ void CellularDataService::OnStart() TELEPHONY_LOGE("CellularDataService has already started."); return; } + RunnerPool::GetInstance().Init(); if (!Init()) { TELEPHONY_LOGE("failed to init CellularDataService"); return; @@ -98,13 +100,12 @@ int32_t CellularDataService::Dump(std::int32_t fd, const std::vectorRun(); if (!registerToService_) { bool ret = Publish(DelayedRefSingleton::GetInstance().AsObject()); if (!ret) { diff --git a/services/src/runner_pool.cpp b/services/src/runner_pool.cpp new file mode 100644 index 00000000..abe39636 --- /dev/null +++ b/services/src/runner_pool.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2023 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. + */ + +#include "runner_pool.h" + +#include "telephony_log_wrapper.h" + +namespace OHOS { +namespace Telephony { +RunnerPool RunnerPool::runnerPool_; + +RunnerPool &RunnerPool::GetInstance() +{ + return runnerPool_; +} + +void RunnerPool::Init() +{ + if (isInit_) { + TELEPHONY_LOGI("RunnerPool has init"); + return; + } + commonRunner_ = CreateRunner("CellularDataRunner"); + if (commonRunner_ == nullptr) { + return; + } + isInit_ = true; + TELEPHONY_LOGI("RunnerPool init success"); +} + +std::shared_ptr RunnerPool::CreateRunner(const std::string name) +{ + auto runner = AppExecFwk::EventRunner::Create(name); + if (runner == nullptr) { + TELEPHONY_LOGE("%{public}s runner create thread fail!", name.c_str()); + return nullptr; + } + runner->Run(); + return runner; +} + +std::shared_ptr RunnerPool::GetCommonRunner() +{ + return commonRunner_; +} +} // namespace Telephony +} // namespace OHOS \ No newline at end of file -- Gitee