GCC Code Coverage Report


Directory: ./
File: openvdb/openvdb/openvdb.cc
Date: 2022-07-25 17:40:05
Exec Total Coverage
Lines: 21 21 100.0%
Functions: 2 2 100.0%
Branches: 25 46 54.3%

Line Branch Exec Source
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3
4 #include "openvdb.h"
5 #include "io/DelayedLoadMetadata.h"
6 #include "points/PointDataGrid.h"
7 #include "tools/PointIndexGrid.h"
8 #include "util/logging.h"
9
10 #include <atomic>
11 #include <mutex>
12
13 #ifdef OPENVDB_USE_BLOSC
14 #include <blosc.h>
15 #endif
16
17 #if OPENVDB_ABI_VERSION_NUMBER <= 6
18 #error ABI <= 6 is no longer supported
19 #endif
20
21 // If using an OPENVDB_ABI_VERSION_NUMBER that has been deprecated, issue an
22 // error directive. This can be optionally suppressed by defining:
23 // OPENVDB_USE_DEPRECATED_ABI_<VERSION>=ON.
24 #ifndef OPENVDB_USE_DEPRECATED_ABI_7
25 #if OPENVDB_ABI_VERSION_NUMBER == 7
26 #error ABI = 7 is deprecated, CMake option OPENVDB_USE_DEPRECATED_ABI_7 suppresses this error
27 #endif
28 #endif
29 #ifndef OPENVDB_USE_DEPRECATED_ABI_8
30 #if OPENVDB_ABI_VERSION_NUMBER == 8
31 #error ABI = 8 is deprecated, CMake option OPENVDB_USE_DEPRECATED_ABI_8 suppresses this error
32 #endif
33 #endif
34
35 // If using a future OPENVDB_ABI_VERSION_NUMBER, issue an error directive.
36 // This can be optionally suppressed by defining:
37 // OPENVDB_USE_FUTURE_ABI_<VERSION>=ON.
38 #ifndef OPENVDB_USE_FUTURE_ABI_10
39 #if OPENVDB_ABI_VERSION_NUMBER == 10
40 #error ABI = 10 is still in active development and has not been finalized, \
41 CMake option OPENVDB_USE_FUTURE_ABI_10 suppresses this error
42 #endif
43 #endif
44
45 namespace openvdb {
46 OPENVDB_USE_VERSION_NAMESPACE
47 namespace OPENVDB_VERSION_NAME {
48
49 namespace {
50 // Declare this at file scope to ensure thread-safe initialization.
51 std::mutex sInitMutex;
52 std::atomic<bool> sIsInitialized{false};
53 }
54
55 /// @todo Change registerX() methods to simply be register()...
56
1/2
✓ Branch 11 taken 323 times.
✗ Branch 12 not taken.
1292 template <typename GridT> struct RegisterGrid { inline void operator()() { GridT::registerGrid(); } };
57
2/4
✓ Branch 17 taken 323 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 323 times.
✗ Branch 21 not taken.
1938 template <typename MetaT> struct RegisterMeta { inline void operator()() { MetaT::registerType(); } };
58
1/2
✓ Branch 8 taken 323 times.
✗ Branch 9 not taken.
969 template <typename MapT> struct RegisterMap { inline void operator()() { MapT::registerMap(); } };
59
60 void
61
2/2
✓ Branch 0 taken 323 times.
✓ Branch 1 taken 17 times.
340 initialize()
62 {
63
2/2
✓ Branch 0 taken 323 times.
✓ Branch 1 taken 17 times.
340 if (sIsInitialized.load(std::memory_order_acquire)) return;
64 std::lock_guard<std::mutex> lock(sInitMutex);
65
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 323 times.
323 if (sIsInitialized.load(std::memory_order_acquire)) return; // Double-checked lock
66
67 logging::initialize();
68
69 // Register metadata.
70
1/2
✓ Branch 1 taken 323 times.
✗ Branch 2 not taken.
323 Metadata::clearRegistry();
71 MetaTypes::foreach<RegisterMeta>();
72
73 // Register maps
74
1/2
✓ Branch 1 taken 323 times.
✗ Branch 2 not taken.
323 math::MapRegistry::clear();
75 MapTypes::foreach<RegisterMap>();
76
77 // Register common grid types.
78
1/2
✓ Branch 1 taken 323 times.
✗ Branch 2 not taken.
323 GridBase::clearRegistry();
79 GridTypes::foreach<RegisterGrid>();
80
81 // @note String grids types are deprecated but we still register them
82 // as supported serializable types for backward compatibility. This
83 // will likely be removed in a future major version
84 OPENVDB_NO_DEPRECATION_WARNING_BEGIN
85
1/2
✓ Branch 1 taken 323 times.
✗ Branch 2 not taken.
323 StringGrid::registerGrid();
86 OPENVDB_NO_DEPRECATION_WARNING_END
87
88 // Register types associated with point index grids.
89
2/4
✓ Branch 1 taken 323 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 323 times.
✗ Branch 5 not taken.
323 Metadata::registerType(typeNameAsString<PointIndex32>(), Int32Metadata::createMetadata);
90
2/4
✓ Branch 1 taken 323 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 323 times.
✗ Branch 5 not taken.
323 Metadata::registerType(typeNameAsString<PointIndex64>(), Int64Metadata::createMetadata);
91
92 // Register types associated with point data grids.
93
1/2
✓ Branch 1 taken 323 times.
✗ Branch 2 not taken.
323 points::internal::initialize();
94
95 #ifdef OPENVDB_USE_BLOSC
96
1/2
✓ Branch 1 taken 323 times.
✗ Branch 2 not taken.
323 blosc_init();
97
2/4
✓ Branch 1 taken 323 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 323 times.
323 if (blosc_set_compressor("lz4") < 0) {
98 OPENVDB_LOG_WARN("Blosc LZ4 compressor is unavailable");
99 }
100 /// @todo blosc_set_nthreads(int nthreads);
101 #endif
102
103 #ifdef __ICC
104 // Disable ICC "assignment to statically allocated variable" warning.
105 // This assignment is mutex-protected and therefore thread-safe.
106 __pragma(warning(disable:1711))
107 #endif
108
109 sIsInitialized.store(true, std::memory_order_release);
110
111 #ifdef __ICC
112 __pragma(warning(default:1711))
113 #endif
114 }
115
116
117 void
118 342 uninitialize()
119 {
120 std::lock_guard<std::mutex> lock(sInitMutex);
121 #ifdef __ICC
122 // Disable ICC "assignment to statically allocated variable" warning.
123 // This assignment is mutex-protected and therefore thread-safe.
124 __pragma(warning(disable:1711))
125 #endif
126
127 sIsInitialized.store(false, std::memory_order_seq_cst); // Do we need full memory order?
128
129 #ifdef __ICC
130 __pragma(warning(default:1711))
131 #endif
132
133
1/2
✓ Branch 1 taken 342 times.
✗ Branch 2 not taken.
342 Metadata::clearRegistry();
134
1/2
✓ Branch 1 taken 342 times.
✗ Branch 2 not taken.
342 GridBase::clearRegistry();
135
1/2
✓ Branch 1 taken 342 times.
✗ Branch 2 not taken.
342 math::MapRegistry::clear();
136
1/2
✓ Branch 1 taken 342 times.
✗ Branch 2 not taken.
342 points::internal::uninitialize();
137
138 #ifdef OPENVDB_USE_BLOSC
139 // We don't want to destroy Blosc, because it might have been
140 // initialized by some other library.
141 //blosc_destroy();
142 #endif
143 342 }
144
145 } // namespace OPENVDB_VERSION_NAME
146 } // namespace openvdb
147