[PATCH] D19271: Change CALL_ONCE_INITIALIZATION implementation to use static initialization
Kostya Serebryany via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 19 18:09:27 PDT 2016
kcc added a reviewer: rnk.
kcc added a comment.
Reid, are function scope statics thread-safe with VC++ 2013?
================
Comment at: include/llvm/PassSupport.h:35
@@ +34,3 @@
+#define CALL_ONCE_INITIALIZATION(function) \
+ static bool init_once([&] { \
+ function(Registry); \
----------------
joker.eph wrote:
> kcc wrote:
> > kcc wrote:
> > > Mmm. I am probably missing something trivial (c++11-ish), but how is this going to work?
> > > For me it looks like you define a static bool function, but never call it.
> > Aaaah, init_once is a bool variable, not a function. Oh, how much this is confusing...
> > Will this work with the versions of Visual C++ we use for LLVM?
> > I remember that static initialization was broken there (until recently?)
> >
> > Why not std::call_once?
> Yeah it would deserve a comment probably :)
> I don't know if static initialization is safe in MSVC 2013 (I know it was announced to be "fixed", but don't know which version).
>
> `std::call_once` require `<mutex>`, and I was worried of portability (I had trouble last time I tried to include it), and because of that we have an abstraction of mutex in libSupport I believe).
>
If you can make it
static bool initialized_once = ...
it will be much more clear and not require a comment.
http://reviews.llvm.org/D19271
More information about the llvm-commits
mailing list