1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_MULTI_THREAD_BUILD_MANAGER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_MULTI_THREAD_BUILD_MANAGER_H 18 19 #include <functional> 20 #include <mutex> 21 #include <map> 22 23 #include "base/utils/macros.h" 24 #include "base/utils/noncopyable.h" 25 #include "core/components_ng/base/ui_node.h" 26 27 namespace OHOS::Ace { 28 class ACE_EXPORT MultiThreadBuildManager { 29 public: 30 static MultiThreadBuildManager& GetInstance(); 31 static void InitOnUIThread(); 32 static bool IsOnUIThread(); 33 static bool CheckOnUIThread(); 34 static bool CheckNodeOnValidThread(NG::UINode* node); 35 static void SetIsThreadSafeNodeScope(bool isThreadSafeNodeScope); 36 static bool IsThreadSafeNodeScope(); 37 bool PostAsyncUITask(int32_t contextId, std::function<void()>&& asyncUITask, 38 std::function<void()>&& onFinishTask); 39 bool PostUITask(int32_t contextId, std::function<void()>&& uiTask); 40 bool PostUITaskAndWait(int32_t contextId, std::function<void()>&& uiTask); 41 private: 42 MultiThreadBuildManager(); 43 void InitAsyncUITaskQueue(); 44 static thread_local bool isThreadSafeNodeScope_; 45 static thread_local bool isUIThread_; 46 ACE_DISALLOW_COPY_AND_MOVE(MultiThreadBuildManager); 47 }; 48 } // namespace OHOS::Ace 49 50 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_MULTI_THREAD_BUILD_MANAGER_H 51