From 64db3905a73d16e8cabb0d01e616c71861585eca Mon Sep 17 00:00:00 2001 From: gaoqiang_strong Date: Fri, 1 Jul 2022 11:27:34 +0800 Subject: [PATCH 1/4] add lock for dscreenmap Signed-off-by: gaoqiang_strong --- .../sourceservice/dscreenmgr/src/dscreen_manager.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/services/screenservice/sourceservice/dscreenmgr/src/dscreen_manager.cpp b/services/screenservice/sourceservice/dscreenmgr/src/dscreen_manager.cpp index 461f5805..4b4c31bd 100644 --- a/services/screenservice/sourceservice/dscreenmgr/src/dscreen_manager.cpp +++ b/services/screenservice/sourceservice/dscreenmgr/src/dscreen_manager.cpp @@ -218,6 +218,7 @@ int32_t DScreenManager::EnableDistributedScreen(const std::string &devId, const std::string dScreenIdx = devId + SEPERATOR + dhId; std::shared_ptr dScreen = nullptr; + std::lock_guard lock(dScreenMapMtx_); if (dScreens_.count(dScreenIdx) != 0) { dScreen = dScreens_[dScreenIdx]; } @@ -248,6 +249,7 @@ int32_t DScreenManager::DisableDistributedScreen(const std::string &devId, const GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); std::string dScreenIdx = devId + SEPERATOR + dhId; + std::lock_guard lock(dScreenMapMtx_); if (dScreens_.count(dScreenIdx) == 0) { DHLOGE("dscreen not found, devId: %s, dhId: %s", GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); @@ -310,6 +312,7 @@ void DScreenManager::GetScreenDumpInfo(std::string &result) DHLOGI("GetScreenDumpInfo."); result.clear(); result.append("RemoteScreens OnLine:\n[\n"); + std::lock_guard lock(dScreenMapMtx_); if (dScreens_.size() == 0) { result.append("]"); DHLOGD("no virtualscreen"); @@ -448,6 +451,7 @@ void DScreenManager::HandleNotifySetUpResult(const std::string &remoteDevId, con std::string errContent = eventContentJson[KEY_ERR_CONTENT]; std::string dScreenIdx = remoteDevId + SEPERATOR + dhId; + std::lock_guard lock(dScreenMapMtx_); if (dScreens_.count(dScreenIdx) == 0) { DHLOGE("dScreen not found, remoteDevId:%s, dhId:%s", GetAnonyString(remoteDevId).c_str(), GetAnonyString(dhId).c_str()); -- Gitee From f5f82e0f6f679575a3a39336e586512a9190aed4 Mon Sep 17 00:00:00 2001 From: gaoqiang_strong Date: Fri, 1 Jul 2022 17:02:26 +0800 Subject: [PATCH 2/4] fix crash bug Signed-off-by: gaoqiang_strong --- common/BUILD.gn | 1 + common/include/dscreen_sa_process_state.h | 25 ++++++++ common/src/dscreen_sa_process_state.cpp | 63 +++++++++++++++++++ .../src/dscreen_sink_service.cpp | 4 +- .../src/dscreen_source_service.cpp | 4 +- 5 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 common/include/dscreen_sa_process_state.h create mode 100644 common/src/dscreen_sa_process_state.cpp diff --git a/common/BUILD.gn b/common/BUILD.gn index 897d71ce..b9bf72d7 100644 --- a/common/BUILD.gn +++ b/common/BUILD.gn @@ -27,6 +27,7 @@ ohos_shared_library("distributed_screen_utils") { sources = [ "src/dscreen_hisysevent.cpp", "src/dscreen_log.cpp", + "src/dscreen_sa_process_state.cpp", "src/dscreen_util.cpp", ] diff --git a/common/include/dscreen_sa_process_state.h b/common/include/dscreen_sa_process_state.h new file mode 100644 index 00000000..95e560cc --- /dev/null +++ b/common/include/dscreen_sa_process_state.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2022 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 DSCREEN_SA_PROCESS_STATE_H +#define DSCREEN_SA_PROCESS_STATE_H + +namespace OHOS { +namespace DistributedHardware { +void SetSinkProcessExit(); +void SetSourceProcessExit(); +} // namespace DistributedHardware +} // namespace OHOS +#endif // DSCREEN_SA_PROCESS_STATE_H diff --git a/common/src/dscreen_sa_process_state.cpp b/common/src/dscreen_sa_process_state.cpp new file mode 100644 index 00000000..4f984552 --- /dev/null +++ b/common/src/dscreen_sa_process_state.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2022 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 "dscreen_sa_process_state.h" + +#include + +#include "dscreen_constants.h" +#include "dscreen_hisysevent.h" +#include "dscreen_log.h" + +namespace OHOS { +namespace DistributedHardware { +typedef enum { + DSCREEN_SA_EXIT_STATE_START = 0, + DSCREEN_SA_EXIT_STATE_STOP = 1 +} DScreenSAState; + +DScreenSAState g_sinkSAState = DSCREEN_SA_EXIT_STATE_START; +DScreenSAState g_sourceSAState = DSCREEN_SA_EXIT_STATE_START; +std::mutex g_saProcessState; + +void SetSinkProcessExit() +{ + DHLOGI("set sink process exit."); + std::lock_guard autoLock(g_saProcessState); + g_sinkSAState = DSCREEN_SA_EXIT_STATE_STOP; + DHLOGI("g_sourceSAState = %d g_sinkSAState = %d", g_sourceSAState, g_sinkSAState); + if (g_sourceSAState == DSCREEN_SA_EXIT_STATE_START || g_sinkSAState == DSCREEN_SA_EXIT_STATE_START) { + return; + } + DHLOGI("exit sa process success."); + ReportSaEvent(DSCREEN_EXIT, DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID, "dscreen sink sa exit success."); + exit(0); +} + +void SetSourceProcessExit() +{ + DHLOGI("set sources process exit."); + std::lock_guard autoLock(g_saProcessState); + g_sourceSAState = DSCREEN_SA_EXIT_STATE_STOP; + DHLOGI("g_sourceSAState = %d g_sinkSAState = %d", g_sourceSAState, g_sinkSAState); + if (g_sourceSAState == DSCREEN_SA_EXIT_STATE_START || g_sinkSAState == DSCREEN_SA_EXIT_STATE_START) { + return; + } + DHLOGI("exit sa process success."); + ReportSaEvent(DSCREEN_EXIT, DISTRIBUTED_HARDWARE_SCREEN_SOURCE_SA_ID, "dscreen source sa exit success."); + exit(0); +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/services/screenservice/sinkservice/dscreenservice/src/dscreen_sink_service.cpp b/services/screenservice/sinkservice/dscreenservice/src/dscreen_sink_service.cpp index 8da0e912..42d84402 100644 --- a/services/screenservice/sinkservice/dscreenservice/src/dscreen_sink_service.cpp +++ b/services/screenservice/sinkservice/dscreenservice/src/dscreen_sink_service.cpp @@ -26,6 +26,7 @@ #include "dscreen_errcode.h" #include "dscreen_hisysevent.h" #include "dscreen_log.h" +#include "dscreen_sa_process_state.h" #include "dscreen_util.h" namespace OHOS { @@ -79,8 +80,7 @@ int32_t DScreenSinkService::ReleaseSink() DHLOGI("ReleaseSink"); ScreenRegionManager::GetInstance().ReleaseAllRegions(); DHLOGI("exit sink sa process"); - ReportSaEvent(DSCREEN_EXIT, DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID, "dscreen sink sa exit success."); - exit(0); + SetSinkProcessExit(); return DH_SUCCESS; } diff --git a/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp b/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp index bae8b5ac..00e8cd8d 100644 --- a/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp +++ b/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp @@ -26,6 +26,7 @@ #include "dscreen_errcode.h" #include "dscreen_hisysevent.h" #include "dscreen_log.h" +#include "dscreen_sa_process_state.h" #include "dscreen_util.h" namespace OHOS { @@ -95,8 +96,7 @@ int32_t DScreenSourceService::ReleaseSource() return ret; } DHLOGI("exit source sa process"); - ReportSaEvent(DSCREEN_EXIT, DISTRIBUTED_HARDWARE_SCREEN_SOURCE_SA_ID, "dscreen source sa exit success."); - exit(0); + SetSourceProcessExit(); return DH_SUCCESS; } -- Gitee From 49cdbcbf3146f301a0dcb03353322dc6c9bba33f Mon Sep 17 00:00:00 2001 From: gaoqiang_strong Date: Fri, 1 Jul 2022 17:07:53 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=9D=E8=AF=81=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=87=8A=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gaoqiang_strong --- .../sinkservice/dscreenservice/src/dscreen_sink_service.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/services/screenservice/sinkservice/dscreenservice/src/dscreen_sink_service.cpp b/services/screenservice/sinkservice/dscreenservice/src/dscreen_sink_service.cpp index 42d84402..8cb6cf25 100644 --- a/services/screenservice/sinkservice/dscreenservice/src/dscreen_sink_service.cpp +++ b/services/screenservice/sinkservice/dscreenservice/src/dscreen_sink_service.cpp @@ -24,7 +24,6 @@ #include "dscreen_constants.h" #include "dscreen_errcode.h" -#include "dscreen_hisysevent.h" #include "dscreen_log.h" #include "dscreen_sa_process_state.h" #include "dscreen_util.h" -- Gitee From 5a3888d8d2587f70f3d98f402524b78001de68bc Mon Sep 17 00:00:00 2001 From: gaoqiang_strong Date: Fri, 1 Jul 2022 17:18:04 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=9D=E8=AF=81=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=87=8A=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gaoqiang_strong --- common/src/dscreen_sa_process_state.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/src/dscreen_sa_process_state.cpp b/common/src/dscreen_sa_process_state.cpp index 4f984552..ae8f53ee 100644 --- a/common/src/dscreen_sa_process_state.cpp +++ b/common/src/dscreen_sa_process_state.cpp @@ -23,10 +23,10 @@ namespace OHOS { namespace DistributedHardware { -typedef enum { +enum DScreenSAState : uint32_t { DSCREEN_SA_EXIT_STATE_START = 0, DSCREEN_SA_EXIT_STATE_STOP = 1 -} DScreenSAState; +}; DScreenSAState g_sinkSAState = DSCREEN_SA_EXIT_STATE_START; DScreenSAState g_sourceSAState = DSCREEN_SA_EXIT_STATE_START; -- Gitee