fix crash bug

Signed-off-by: gaoqiang_strong <gaoqiang64@huawei.com>
This commit is contained in:
gaoqiang_strong
2022-07-01 17:02:26 +08:00
parent cd0bc5ac2d
commit b8de6a7afa
5 changed files with 93 additions and 4 deletions
+1
View File
@@ -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",
]
+25
View File
@@ -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
+63
View File
@@ -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 <mutex>
#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<std::mutex> 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<std::mutex> 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
@@ -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;
}
@@ -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;
}