Ticket #50998: root5-threadlocalstorage.diff

File root5-threadlocalstorage.diff, 7.0 KB (added by mojca (Mojca Miklavec), 8 years ago)

An upstream patch to fix an issue with C++11 and thread local storage

  • Portfile

     
    5050select.group        root
    5151select.file         ${filespath}/${name}
    5252
    53 patchfiles-append   patch-math-mathmore-src-GSLMultiFit.h.diff
     53patchfiles-append   patch-math-mathmore-src-GSLMultiFit.h.diff \
     54                    patch-upstram-core-thread-inc-ThreadLocalStorage.h.diff
    5455
    5556post-patch {
    5657#   reinplace "s|-lfreetype| \`freetype-config --libs\`|g" ${worksrcpath}/config/root-config.in
  • files/patch-upstram-core-thread-inc-ThreadLocalStorage.h.diff

     
     1From 9560b6cd39a1a795ad85b9e39c74408e830300a8 Mon Sep 17 00:00:00 2001
     2From: Fons Rademakers <Fons.Rademakers@cern.ch>
     3Date: Wed, 30 Mar 2016 11:34:43 +0200
     4Subject: [PATCH] backport from master so C++11 mode works with Xcode 7.3 again
     5 (fixes ROOT-8076).
     6
     7---
     8 core/thread/inc/ThreadLocalStorage.h | 89 ++++++++++++++++++++++++++++++------
     9 1 file changed, 75 insertions(+), 14 deletions(-)
     10
     11diff --git a/core/thread/inc/ThreadLocalStorage.h b/core/thread/inc/ThreadLocalStorage.h
     12index a4e4bdf..5df2151 100644
     13--- core/thread/inc/ThreadLocalStorage.h
     14+++ core/thread/inc/ThreadLocalStorage.h
     15@@ -1,6 +1,6 @@
     16 // @(#)root/thread:$Id$
     17 /*
     18- * Copyright (c) 2006-2011 High Performance Computing Center Stuttgart,
     19+ * Copyright (c) 2006-2011 High Performance Computing Center Stuttgart,
     20  *                         University of Stuttgart.  All rights reserved.
     21  * Author: Rainer Keller, HLRS
     22  * Modified: Fons Rademakers, CERN
     23@@ -35,11 +35,32 @@
     24  *  - We do NOT allow something like
     25  *       func (a, TTHREAD_TLS_SET(int, my_var, 5));
     26  *    as we do not use the gcc-extension of returning macro-values.
     27+ *
     28+ * C++11 requires the implementation of the thread_local storage but
     29+ * a few platforms do not yet implement it.
     30+ *
     31+ *  For simple type use:
     32+ *      TTHREAD_TLS(int) varname;
     33+ *
     34+ *  For array of simple type use:
     35+ *      TTHREAD_TLS_ARRAY(int, arraysize, varname);
     36+ *
     37+ *  For object use:
     38+ *      TTHREAD_TLS_DECL(classname, varname);
     39+ *      TTHREAD_TLS_DECL_ARG(classname, varname, arg);
     40+ *      TTHREAD_TLS_DECL_ARG2(classname, varname, arg1, arg2);
     41+ *
     42  */
     43-
     44+
     45 #ifndef ROOT_ThreadLocalStorage
     46 #define ROOT_ThreadLocalStorage
     47 
     48+#include <stddef.h>
     49+
     50+#ifdef __cplusplus
     51+#include "Rtypes.h"
     52+#endif
     53+
     54 #ifndef ROOT_RConfig
     55 #include "RConfig.h"
     56 #endif
     57@@ -67,17 +88,23 @@
     58 
     59 #if __cplusplus >= 201103L
     60 
     61-// Note: it would be tempting to use __has_feature(cxx_thread_local) but despite
     62-// documentation claims it support for it ... it is in fact ineffective (return
     63-// a false negative).
     64 // Clang 3.4 also support SD-6 (feature test macros __cpp_*), but no thread local macro
     65-#  if defined(__clang__) && (__clang_major__ >= 3 && __clang_minor__ >= 3)
     66+#  if defined(__clang__)
     67+
     68+#    if __has_feature(cxx_thread_local)
     69      // thread_local was added in Clang 3.3
     70      // Still requires libstdc++ from GCC 4.8
     71      // For that __GLIBCXX__ isn't good enough
     72-#    define R__HAS_THREAD_LOCAL
     73+     // Also the MacOS build of clang does *not* support thread local yet.
     74+#      define R__HAS_THREAD_LOCAL
     75+#    else
     76+#      define R__HAS___THREAD
     77+#    endif
     78+
     79+#  elif defined(__INTEL_COMPILER)
     80+#    define R__HAS__THREAD
     81 
     82-#  elif defined(__GNUG__) && (__GNUC__ <= 4 && __GNUC_MINOR__ < 80)
     83+#  elif defined(__GNUG__) && (__GNUC__ <= 4 && __GNUC_MINOR__ < 8)
     84     // The C++11 thread_local keyword is supported in GCC only since 4.8
     85 #    define R__HAS___THREAD
     86 #  else
     87@@ -95,25 +122,29 @@
     88 #ifdef __CINT__
     89 
     90 #  define TTHREAD_TLS(type) static type
     91-#  define TTHREAD_TLS_ARRAY(type,size,name) static type name[size];
     92+#  define TTHREAD_TLS_ARRAY(type,size,name) static type name[size]
     93 #  define TTHREAD_TLS_PTR(name) &name
     94 
     95 #elif defined(R__HAS_THREAD_LOCAL)
     96 
     97 #  define TTHREAD_TLS(type) thread_local type
     98-#  define TTHREAD_TLS_ARRAY(type,size,name) thread_local type name[size];
     99+#  define TTHREAD_TLS_ARRAY(type,size,name) thread_local type name[size]
     100 #  define TTHREAD_TLS_PTR(name) &name
     101 
     102+#  define TTHREAD_TLS_DECL(type, name) thread_local type name
     103+#  define TTHREAD_TLS_DECL_ARG(type, name, arg) thread_local type name(arg)
     104+#  define TTHREAD_TLS_DECL_ARG2(type, name, arg1, arg2) thread_local type name(arg1,arg2)
     105+
     106 #elif defined(R__HAS___THREAD)
     107 
     108 #  define TTHREAD_TLS(type)  static __thread type
     109-#  define TTHREAD_TLS_ARRAY(type,size,name) static __thread type name[size];
     110+#  define TTHREAD_TLS_ARRAY(type,size,name) static __thread type name[size]
     111 #  define TTHREAD_TLS_PTR(name) &name
     112 
     113 #elif defined(R__HAS_DECLSPEC_THREAD)
     114 
     115 #  define TTHREAD_TLS(type) static __declspec(thread) type
     116-#  define TTHREAD_TLS_ARRAY(type,size,name) static __declspec(thread) type name[size];
     117+#  define TTHREAD_TLS_ARRAY(type,size,name) static __declspec(thread) type name[size]
     118 #  define TTHREAD_TLS_PTR(name) &name
     119 
     120 #elif defined(R__HAS_PTHREAD)
     121@@ -126,7 +157,7 @@ template <typename type> class TThreadTLSWrapper
     122 private:
     123    pthread_key_t  fKey;
     124    type           fInitValue;
     125-   
     126+
     127    static void key_delete(void *arg) {
     128       assert (NULL != arg);
     129       delete (type*)(arg);
     130@@ -210,12 +241,14 @@ template <typename type,int size> class TThreadTLSArrayWrapper
     131    operator type*() {
     132       return get();
     133    }
     134-   
     135+
     136 };
     137 
     138 #  define TTHREAD_TLS(type) static TThreadTLSWrapper<type>
     139 #  define TTHREAD_TLS_ARRAY(type,size,name) static TThreadTLSArrayWrapper<type,size> name;
     140 #  define TTHREAD_TLS_PTR(name) &(name.get())
     141+#  define TTHREAD_TLS_OBJ(index,type,name) type &name( TTHREAD_TLS_INIT<index,type>() )
     142+
     143 #else
     144 
     145 #error "No Thread Local Storage (TLS) technology for this platform specified."
     146@@ -223,6 +256,34 @@ template <typename type,int size> class TThreadTLSArrayWrapper
     147 #endif
     148 
     149 // Available on all platforms
     150+
     151+
     152+// Neither TTHREAD_TLS_DECL_IMPL and TTHREAD_TLS_INIT
     153+// do not delete the object at the end of the process.
     154+
     155+#define TTHREAD_TLS_DECL_IMPL(type, name, ptr, arg) \
     156+   TTHREAD_TLS(type *) ptr = 0; \
     157+   if (!ptr) ptr = new type(arg); \
     158+   type &name = *ptr;
     159+
     160+#define TTHREAD_TLS_DECL_IMPL2(type, name, ptr, arg1, arg2) \
     161+   TTHREAD_TLS(type *) ptr = 0; \
     162+   if (!ptr) ptr = new type(arg1,arg2); \
     163+   type &name = *ptr;
     164+
     165+#ifndef TTHREAD_TLS_DECL
     166+
     167+#define TTHREAD_TLS_DECL(type, name) \
     168+   TTHREAD_TLS_DECL_IMPL(type,name,_R__JOIN_(ptr,__LINE__),)
     169+
     170+#define TTHREAD_TLS_DECL_ARG(type, name, arg) \
     171+   TTHREAD_TLS_DECL_IMPL(type,name,_R__JOIN_(ptr,__LINE__),arg)
     172+
     173+#define TTHREAD_TLS_DECL_ARG2(type, name, arg1, arg2) \
     174+   TTHREAD_TLS_DECL_IMPL2(type,name,_R__JOIN_(ptr,__LINE__),arg1,arg2)
     175+
     176+#endif
     177+
     178 template <int marker, typename T>
     179 T &TTHREAD_TLS_INIT() {
     180    TTHREAD_TLS(T*) ptr = NULL;