diff --git a/BUILD.gn b/BUILD.gn index 0d6355613bb019f632ac97c981886e23c87fa2ac..45ebaa595762e847abd41897dea70afea68a8734 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 0000000000000000000000000000000000000000..eec28b58869ea7b45d7677651cd92635b347ebc4 --- /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 6dab123dfd89e089cae1fb6a90b5a2f0f68a75e8..98fb41743d4c0b5388da362edee527d765dec831 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 a7f4f1ad021ee77948c19b72911a678062463904..94e69829932f48d56ed6d7cc6f2c378e6227493a 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 0000000000000000000000000000000000000000..abe3963641f3908a1473341b9d57534a2ce0691d --- /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