Skip to content

Commit dfe78df

Browse files
committed
Make DispatchInitializer thread-safe using function-local static
1 parent 5b9435c commit dfe78df

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

unittests/CppInterOp/Utils.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ struct DispatchInitializer {
3535
DispatchInitializer(DispatchInitializer&&) noexcept = default;
3636
DispatchInitializer& operator=(DispatchInitializer&&) noexcept = default;
3737
};
38-
// FIXME: Make this threadsafe by moving it as a function static.
39-
DispatchInitializer g_dispatch_init;
38+
// Thread-safe initialization using function-local static
39+
static DispatchInitializer& GetDispatchInitializer() {
40+
static DispatchInitializer instance;
41+
return instance;
42+
}
43+
static DispatchInitializer& g_dispatch_init = GetDispatchInitializer();
4044
} // namespace
4145
#endif
4246

0 commit comments

Comments
 (0)