Blender
V5.3
source
blender
depsgraph
intern
depsgraph_registry.cc
Go to the documentation of this file.
1
/* SPDX-FileCopyrightText: 2019 Blender Authors
2
*
3
* SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9
#include "
BLI_map.hh
"
10
#include "
BLI_mutex.hh
"
11
#include "
BLI_vector_set.hh
"
12
13
#include "
intern/depsgraph_registry.hh
"
14
15
#include "
intern/depsgraph.hh
"
16
17
namespace
blender::deg
{
18
19
/* Global registry for dependency graphs associated with a main database.
20
*
21
* Threads may add or remove depsgraphs for different mains concurrently
22
* (for example for preview rendering), but not the same main. */
23
24
/* Use pointer for map value to ensure span returned by get_all_registered_graphs
25
* remains unchanged as other mains are added or removed. */
26
using
GraphSetPtr
= std::unique_ptr<VectorSet<Depsgraph *>>;
27
struct
GraphRegistry
{
28
Map<Main *, GraphSetPtr>
map
;
29
Mutex
mutex
;
30
};
31
32
static
GraphRegistry
&
get_graph_registry
()
33
{
34
static
GraphRegistry
graph_registry;
35
return
graph_registry;
36
}
37
38
void
register_graph
(
Depsgraph
*depsgraph)
39
{
40
GraphRegistry
&graph_registry =
get_graph_registry
();
41
Main
*bmain = depsgraph->
bmain
;
42
43
std::lock_guard
lock
{graph_registry.
mutex
};
44
graph_registry.
map
45
.lookup_or_add_cb(bmain, []() {
return
std::make_unique<VectorSet<Depsgraph *>>(); })
46
->add_new(depsgraph);
47
}
48
49
void
unregister_graph
(
Depsgraph
*depsgraph)
50
{
51
Main
*bmain = depsgraph->
bmain
;
52
GraphRegistry
&graph_registry =
get_graph_registry
();
53
54
std::lock_guard
lock
{graph_registry.
mutex
};
55
GraphSetPtr
&graphs = graph_registry.
map
.lookup(bmain);
56
graphs->remove(depsgraph);
57
58
/* If this was the last depsgraph associated with the main, remove the main entry as well. */
59
if
(graphs->is_empty()) {
60
graph_registry.
map
.remove(bmain);
61
}
62
}
63
64
Span<Depsgraph *>
get_all_registered_graphs
(
Main
*bmain)
65
{
66
GraphRegistry
&graph_registry =
get_graph_registry
();
67
std::lock_guard
lock
{graph_registry.
mutex
};
68
GraphSetPtr
*graphs = graph_registry.
map
.lookup_ptr(bmain);
69
if
(graphs) {
70
return
**graphs;
71
}
72
return
{};
73
}
74
75
}
// namespace blender::deg
BLI_map.hh
BLI_mutex.hh
BLI_vector_set.hh
lock
volatile int lock
Definition
atomic_ops_unix.h:0
blender::Map
Definition
BLI_map.hh:129
blender::Span
Definition
BLI_span.hh:74
depsgraph.hh
depsgraph_registry.hh
blender::deg
Definition
DEG_depsgraph_light_linking.hh:15
blender::deg::get_all_registered_graphs
Span< Depsgraph * > get_all_registered_graphs(Main *bmain)
Definition
depsgraph_registry.cc:64
blender::deg::GraphSetPtr
std::unique_ptr< VectorSet< Depsgraph * > > GraphSetPtr
Definition
depsgraph_registry.cc:26
blender::deg::get_graph_registry
static GraphRegistry & get_graph_registry()
Definition
depsgraph_registry.cc:32
blender::deg::unregister_graph
void unregister_graph(Depsgraph *depsgraph)
Definition
depsgraph_registry.cc:49
blender::deg::register_graph
void register_graph(Depsgraph *depsgraph)
Definition
depsgraph_registry.cc:38
blender::Mutex
std::mutex Mutex
Definition
BLI_mutex.hh:51
blender::Main
Definition
BKE_main.hh:243
blender::deg::Depsgraph
Definition
depsgraph.hh:50
blender::deg::Depsgraph::bmain
Main * bmain
Definition
depsgraph.hh:142
blender::deg::GraphRegistry
Definition
depsgraph_registry.cc:27
blender::deg::GraphRegistry::mutex
Mutex mutex
Definition
depsgraph_registry.cc:29
blender::deg::GraphRegistry::map
Map< Main *, GraphSetPtr > map
Definition
depsgraph_registry.cc:28
Generated on
for Blender by
doxygen
1.18.0