From: luozheng <1732036298@qq.com> Date: Wed, 24 Dec 2025 07:13:55 +0000 (+0800) Subject: 解决死机重启后出现两次InitGraphicService() 调用,导致开机后切换界面死机bug X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=refs%2Fchanges%2F2969%2F1;p=mirrors%2FFD230.git 解决死机重启后出现两次InitGraphicService() 调用,导致开机后切换界面死机bug --- diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/src/service/src/graphic_service.cpp b/code/sdk/middleware/services/gui/uikit/proprietary/src/service/src/graphic_service.cpp index 50bd3417a..6b10d7a92 100644 --- a/code/sdk/middleware/services/gui/uikit/proprietary/src/service/src/graphic_service.cpp +++ b/code/sdk/middleware/services/gui/uikit/proprietary/src/service/src/graphic_service.cpp @@ -57,6 +57,8 @@ static uint32_t nativeUITaskId_ = 0xFFFFFFFF; #endif static ThreadId g_rtcEventThreadId; static ThreadId g_mainThreadId; +static bool g_graphicServiceInitialized = false; +static OHOS::GraphicMutex g_initMutex; GraphicService::GraphicService() {} GraphicService::~GraphicService() {} @@ -252,8 +254,24 @@ void GraphicService::SetUpRootView(void) bool GraphicService::InitGraphicService() { + /* Use mutex to prevent race condition during initialization */ + g_initMutex.Lock(); + + /* Check if already initialized to prevent duplicate thread creation */ + //在创建线程之前设置 g_graphicServiceInitialized = true,防止并发初始化 + if (g_graphicServiceInitialized || g_mainThreadId != nullptr || g_rtcEventThreadId != nullptr) { + g_initMutex.Unlock(); + GRAPHIC_LOGW("GraphicService already initialized, skip duplicate initialization\n"); + return true; + } + + /* Set flag early to prevent concurrent initialization */ + g_graphicServiceInitialized = true; + #if !defined(_WIN32) if (!uapi_is_lcd_connect()) { + g_graphicServiceInitialized = false; /* Reset flag on failure */ + g_initMutex.Unlock(); return false; } #endif @@ -273,6 +291,8 @@ bool GraphicService::InitGraphicService() g_rtcEventThreadId = (ThreadId)ThreadCreate((Runnable)GraphicService::RtcEventThread, nullptr, &rtcAttr); if (g_rtcEventThreadId == nullptr) { GRAPHIC_LOGE("%s: create thread fail\n", __func__); + g_graphicServiceInitialized = false; /* Reset flag on failure */ + g_initMutex.Unlock(); return false; } @@ -283,7 +303,11 @@ bool GraphicService::InitGraphicService() g_mainThreadId = (ThreadId)ThreadCreate((Runnable)GraphicService::NativeMainThread, nullptr, &mainAttr); if (g_mainThreadId == nullptr) { GRAPHIC_LOGE("create thread fail\n"); + g_graphicServiceInitialized = false; /* Reset flag on failure */ + g_initMutex.Unlock(); return false; } + + g_initMutex.Unlock(); return true; } diff --git a/code/sdk/zhihui/services/ble_service/bleservice/bleService.c b/code/sdk/zhihui/services/ble_service/bleservice/bleService.c index d65da759e..d70087b9f 100644 --- a/code/sdk/zhihui/services/ble_service/bleservice/bleService.c +++ b/code/sdk/zhihui/services/ble_service/bleservice/bleService.c @@ -2164,9 +2164,11 @@ void svr_ble_bluetooth_init(void) #endif gattc_reg_id(); + #ifndef BOARD_FD272 //FD272没有Ai服务 #ifdef SUPPORT_BLE_SERVICE uapi_Ai_send_service_init(); #endif + #endif g_custom_ble_init_flag = true; return;