解决死机重启后出现两次InitGraphicService() 调用,导致开机后切换界面死机bug 2967/1 2967/head 2971/target/1
authorluozheng <1732036298@qq.com>
Wed, 24 Dec 2025 07:13:55 +0000 (15:13 +0800)
committerluozheng <1732036298@qq.com>
Wed, 24 Dec 2025 07:13:55 +0000 (15:13 +0800)
code/sdk/middleware/services/gui/uikit/proprietary/src/service/src/graphic_service.cpp
code/sdk/zhihui/services/ble_service/bleservice/bleService.c

index 50bd341..6b10d7a 100644 (file)
@@ -57,6 +57,8 @@ static uint32_t nativeUITaskId_ = 0xFFFFFFFF;
 #endif\r
 static ThreadId g_rtcEventThreadId;\r
 static ThreadId g_mainThreadId;\r
+static bool g_graphicServiceInitialized = false;\r
+static OHOS::GraphicMutex g_initMutex;\r
 GraphicService::GraphicService() {}\r
 \r
 GraphicService::~GraphicService() {}\r
@@ -252,8 +254,24 @@ void GraphicService::SetUpRootView(void)
 \r
 bool GraphicService::InitGraphicService()\r
 {\r
+    /* Use mutex to prevent race condition during initialization */\r
+    g_initMutex.Lock();\r
+    \r
+    /* Check if already initialized to prevent duplicate thread creation */\r
+    //在创建线程之前设置 g_graphicServiceInitialized = true,防止并发初始化\r
+    if (g_graphicServiceInitialized || g_mainThreadId != nullptr || g_rtcEventThreadId != nullptr) {\r
+        g_initMutex.Unlock();\r
+        GRAPHIC_LOGW("GraphicService already initialized, skip duplicate initialization\n");\r
+        return true;\r
+    }\r
+    \r
+    /* Set flag early to prevent concurrent initialization */\r
+    g_graphicServiceInitialized = true;\r
+\r
 #if !defined(_WIN32)\r
     if (!uapi_is_lcd_connect()) {\r
+        g_graphicServiceInitialized = false; /* Reset flag on failure */\r
+        g_initMutex.Unlock();\r
         return false;\r
     }\r
 #endif\r
@@ -273,6 +291,8 @@ bool GraphicService::InitGraphicService()
     g_rtcEventThreadId = (ThreadId)ThreadCreate((Runnable)GraphicService::RtcEventThread, nullptr, &rtcAttr);\r
     if (g_rtcEventThreadId == nullptr) {\r
         GRAPHIC_LOGE("%s: create thread fail\n", __func__);\r
+        g_graphicServiceInitialized = false; /* Reset flag on failure */\r
+        g_initMutex.Unlock();\r
         return false;\r
     }\r
 \r
@@ -283,7 +303,11 @@ bool GraphicService::InitGraphicService()
     g_mainThreadId = (ThreadId)ThreadCreate((Runnable)GraphicService::NativeMainThread, nullptr, &mainAttr);\r
     if (g_mainThreadId == nullptr) {\r
         GRAPHIC_LOGE("create thread fail\n");\r
+        g_graphicServiceInitialized = false; /* Reset flag on failure */\r
+        g_initMutex.Unlock();\r
         return false;\r
     }\r
+    \r
+    g_initMutex.Unlock();\r
     return true;\r
 }\r
index d65da75..d70087b 100644 (file)
@@ -2164,9 +2164,11 @@ void svr_ble_bluetooth_init(void)
     #endif\r
     gattc_reg_id();\r
 \r
+    #ifndef BOARD_FD272 //FD272没有Ai服务\r
     #ifdef SUPPORT_BLE_SERVICE\r
     uapi_Ai_send_service_init();\r
     #endif\r
+    #endif\r
 \r
     g_custom_ble_init_flag = true;\r
     return;\r