File tree Expand file tree Collapse file tree 1 file changed +7
-11
lines changed Expand file tree Collapse file tree 1 file changed +7
-11
lines changed Original file line number Diff line number Diff line change @@ -101,10 +101,8 @@ using PlatformVecT = SmallVector<ol_platform_impl_t, 4>;
101
101
static PlatformVecT *PlatformList;
102
102
PlatformVecT &Platforms () { return *PlatformList; }
103
103
104
- static std::atomic_int &GlobalRefCount () {
105
- static std::atomic_int Ref{0 };
106
- return Ref;
107
- }
104
+ static std::mutex InitDeinitMtx;
105
+ static uint32_t RefCount = 0 ;
108
106
109
107
ol_device_handle_t HostDevice () {
110
108
// The host platform is always inserted last
@@ -173,20 +171,18 @@ void initPlugins() {
173
171
}
174
172
175
173
Error olInit_impl () {
176
- // While the refcount increment ensures that only thread performs
177
- // initialization, we need to ensure that other threads are blocked until it
178
- // is completed - hence this mutex.
179
- static std::mutex Init{};
180
- std::lock_guard<std::mutex> Guard{Init};
174
+ std::lock_guard<std::mutex> Guard{InitDeinitMtx};
181
175
182
- if (++GlobalRefCount () == 1 )
176
+ if (++RefCount == 1 )
183
177
initPlugins ();
184
178
185
179
return Error::success ();
186
180
}
187
181
188
182
Error olShutDown_impl () {
189
- if (--GlobalRefCount () != 0 )
183
+ std::lock_guard<std::mutex> Guard{InitDeinitMtx};
184
+
185
+ if (--RefCount != 0 )
190
186
return Error::success ();
191
187
192
188
llvm::Error Result = Error::success ();
You can’t perform that action at this time.
0 commit comments