• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_COMPONENTS_BASE_ELEMENT_REGISTER_MULTI_THREAD_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_ELEMENT_REGISTER_MULTI_THREAD_H
18 
19 #include <shared_mutex>
20 #include <unordered_map>
21 #include "base/memory/referenced.h"
22 #include "core/components_ng/base/ui_node.h"
23 #include "frameworks/base/memory/ace_type.h"
24 
25 namespace OHOS::Ace {
26 using ElementIdType = int32_t;
27 
28 class ACE_EXPORT ElementRegisterMultiThread {
29 public:
30     ACE_FORCE_EXPORT static ElementRegisterMultiThread* GetInstance();
31     bool AddUINodeMultiThread(const RefPtr<NG::UINode>& node);
32     RefPtr<NG::UINode> GetThreadSafeNodeById(ElementIdType elementId);
33     bool RemoveThreadSafeNode(ElementIdType elementId);
34 private:
35     // private constructor
36     ElementRegisterMultiThread() = default;
37     bool AddThreadSafeNode(const RefPtr<NG::UINode>& node);
38 
39     std::shared_mutex threadSafeNodeMapMutex_;
40     std::unordered_map<ElementIdType, WeakPtr<AceType>> threadSafeNodeMap_;
41 
42     ACE_DISALLOW_COPY_AND_MOVE(ElementRegisterMultiThread);
43 };
44 } // namespace OHOS::Ace
45 
46 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_ELEMENT_REGISTER_MULTI_THREAD_H