[Lldb-commits] [lldb] r224310 - Instead of rolling our own, use the C++11 sanctioned solution

Enrico Granata egranata at apple.com
Tue Dec 16 11:10:19 PST 2014


It says #import because of my silly brain, actually
And, yes, it compiles on OS X - clang is quite happy to oblige ObjC directives even if it’s not ObjC code

> On Dec 16, 2014, at 11:03 AM, Zachary Turner <zturner at google.com> wrote:
> 
> Why does this say #import instead of #include?  Does this actually compile on MacOSX?  I'm assuming it's just a typo for #include, but I'm curious why this ever worked at all on any platform.
> 
> On Mon Dec 15 2014 at 8:34:14 PM Enrico Granata <egranata at apple.com <mailto:egranata at apple.com>> wrote:
> Author: enrico
> Date: Mon Dec 15 20:34:13 2014
> New Revision: 224310
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=224310&view=rev <http://llvm.org/viewvc/llvm-project?rev=224310&view=rev>
> Log:
> Instead of rolling our own, use the C++11 sanctioned solution
> 
> Modified:
>     lldb/trunk/source/Core/ConstString.cpp
> 
> Modified: lldb/trunk/source/Core/ConstString.cpp
> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ConstString.cpp?rev=224310&r1=224309&r2=224310&view=diff <http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ConstString.cpp?rev=224310&r1=224309&r2=224310&view=diff>
> ==============================================================================
> --- lldb/trunk/source/Core/ConstString.cpp (original)
> +++ lldb/trunk/source/Core/ConstString.cpp Mon Dec 15 20:34:13 2014
> @@ -11,6 +11,8 @@
>  #include "lldb/Host/Mutex.h"
>  #include "llvm/ADT/StringMap.h"
> 
> +#import <mutex>
> +
>  using namespace lldb_private;
> 
> 
> @@ -184,25 +186,16 @@ protected:
>  // we can't guarantee that some objects won't get destroyed after the
>  // global destructor chain is run, and trying to make sure no destructors
>  // touch ConstStrings is difficult.  So we leak the pool instead.
> -//
> -// FIXME: If we are going to keep it this way we should come up with some
> -// abstraction to "pthread_once" so we don't have to check the pointer
> -// every time.
>  //----------------------------------------------------------------------
>  static Pool &
>  StringPool()
>  {
> -    static Mutex g_pool_initialization_mutex;
> +    static std::once_flag g_pool_initialization_flag;
>      static Pool *g_string_pool = NULL;
> 
> -    if (g_string_pool == NULL)
> -    {
> -        Mutex::Locker initialization_locker(g_pool_initialization_mutex);
> -        if (g_string_pool == NULL)
> -        {
> -            g_string_pool = new Pool();
> -        }
> -    }
> +    std::call_once(g_pool_initialization_flag, [] () {
> +        g_string_pool = new Pool();
> +    });
> 
>      return *g_string_pool;
>  }
> 
> 
> _______________________________________________
> lldb-commits mailing list
> lldb-commits at cs.uiuc.edu <mailto:lldb-commits at cs.uiuc.edu>
> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits <http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits>

Thanks,
- Enrico
📩 egranata@.com ☎️ 27683




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20141216/8c063746/attachment.html>


More information about the lldb-commits mailing list