[llvm-commits] [llvm] r73636 - /llvm/trunk/lib/VMCore/Pass.cpp
Howard Su
howard0su at gmail.com
Wed Jun 17 19:18:37 PDT 2009
I don't think this is worth for this sort of optimization. Double check lock
only optimize out a lock. However since this function is not a freqently
called function, this optimization is not that useful. I suggest you just
lock and check the flag.
On Thu, Jun 18, 2009 at 5:16 AM, Owen Anderson <resistor at mac.com> wrote:
> Author: resistor
> Date: Wed Jun 17 16:16:20 2009
> New Revision: 73636
>
> URL: http://llvm.org/viewvc/llvm-project?rev=73636&view=rev
> Log:
> We need to use double-checked locking for lazy initialization in this case
> when running multithreaded.
>
> Modified:
> llvm/trunk/lib/VMCore/Pass.cpp
>
> Modified: llvm/trunk/lib/VMCore/Pass.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Pass.cpp?rev=73636&r1=73635&r2=73636&view=diff
>
>
> ==============================================================================
> --- llvm/trunk/lib/VMCore/Pass.cpp (original)
> +++ llvm/trunk/lib/VMCore/Pass.cpp Wed Jun 17 16:16:20 2009
> @@ -19,6 +19,8 @@
> #include "llvm/ModuleProvider.h"
> #include "llvm/ADT/STLExtras.h"
> #include "llvm/Support/ManagedStatic.h"
> +#include "llvm/Support/Threading.h"
> +#include "llvm/System/Atomic.h"
> #include <algorithm>
> #include <map>
> #include <set>
> @@ -192,8 +194,20 @@
> // ressurection after llvm_shutdown is run.
> static PassRegistrar *getPassRegistrar() {
> static PassRegistrar *PassRegistrarObj = 0;
> +
> + // Use double-checked locking to safely initialize the registrar when
> + // we're running in multithreaded mode.
> if (!PassRegistrarObj)
> - PassRegistrarObj = new PassRegistrar();
> + if (llvm_is_multithreaded()) {
> + llvm_acquire_global_lock();
> + if (!PassRegistrarObj) {
> + PassRegistrar* tmp = new PassRegistrar();
> + sys::MemoryFence();
> + PassRegistrarObj = tmp;
> + }
> + llvm_release_global_lock();
> + } else
> + PassRegistrarObj = new PassRegistrar();
> return PassRegistrarObj;
> }
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
--
-Howard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20090618/521fd38d/attachment.html>
More information about the llvm-commits
mailing list