• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 #include "js_df_manager.h"
17 
18 #include <unistd.h>
19 
20 #include <mutex>
21 
22 namespace OHOS::AppDataMgrJsKit {
GetInstance()23 JSDFManager &JSDFManager::GetInstance()
24 {
25     static JSDFManager instance;
26     return instance;
27 }
28 
AddNewInfo(void * data)29 void JSDFManager::AddNewInfo(void *data)
30 {
31     std::lock_guard<std::mutex> lockGuard(mapMutex);
32     instances_[data] = 0;
33 }
34 
GetFreedTid(void * data)35 int32_t JSDFManager::GetFreedTid(void *data)
36 {
37     std::lock_guard<std::mutex> lockGuard(mapMutex);
38     int32_t freedTid = 0;
39     auto it = instances_.find(data);
40     if (it != instances_.end()) {
41         auto tid = it->second;
42         if (tid != 0) {
43             freedTid = tid;
44         } else {
45 #if defined(CROSS_PLATFORM)
46             tid = 0;
47 #else
48             tid = gettid();
49 #endif
50             instances_[data] = tid;
51         }
52     }
53     return freedTid;
54 }
55 } // namespace OHOS::AppDataMgrJsKit