• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 FFRT_ENTITY_HPP
17 #define FFRT_ENTITY_HPP
18 
19 #include <unordered_map>
20 #include <list>
21 
22 #include "sync/sync.h"
23 
24 namespace ffrt {
25 struct VersionCtx;
26 
27 struct Entity {
InstanceEntity28     static inline Entity* Instance()
29     {
30         static Entity ins;
31         return &ins;
32     }
33 
34     VersionCtx* VA2Ctx(const void* p, TaskCtx* task);
35     void RecycleVersion();
36 
37     std::list<VersionCtx*> versionTrashcan; // VersionCtx to be deleted
38     std::unordered_map<const void*, VersionCtx*> vaMap;
39 #ifdef MUTEX_PERF // Mutex Lock&Unlock Cycles Statistic
40     xx::mutex criticalMutex_ {"DependencyManager::criticalMutex_"};
41 #else
42     /* It is only used to ensure the consistency between multiple groups of ctx,
43      * and to ensure that the status cannot be changed between the query status and the do action
44      */
45     fast_mutex criticalMutex_;
46 #endif
47 };
48 } // namespace ffrt
49 #endif
50