diff --git a/Filtered_kernel/include/CGAL/Lazy.h b/Filtered_kernel/include/CGAL/Lazy.h index 4daa536683c..55e2aa4c087 100644 --- a/Filtered_kernel/include/CGAL/Lazy.h +++ b/Filtered_kernel/include/CGAL/Lazy.h @@ -784,25 +784,11 @@ private: // which is in particular heavily used for pruning DAGs. static const Self & zero() { -#ifdef CGAL_HAS_THREADS -#if BOOST_MSVC - CGAL_THREAD_LOCAL static Self* z = NULL; - if(z == NULL){ - z = new Self(new Lazy_rep_0()); - } - return *z; -#else - static boost::thread_specific_ptr z; - - if (z.get() == NULL) { - z.reset(new Self(new Lazy_rep_0())); - } - return * z.get(); -#endif -#else - static const Self z = new Lazy_rep_0(); + Lazy_rep_0* ptr = new Lazy_rep_0(); + CGAL_THREAD_LOCAL_DECLARE(Self,z); + CGAL_THREAD_LOCAL_INITIALIZE(Self,z, ptr); + CGAL_THREAD_LOCAL_GET(Self,z); return z; -#endif } Self_rep * ptr() const { return (Self_rep*) PTR; } diff --git a/Installation/include/CGAL/config.h b/Installation/include/CGAL/config.h index d96d3a5477a..05b2b4bb011 100644 --- a/Installation/include/CGAL/config.h +++ b/Installation/include/CGAL/config.h @@ -420,7 +420,7 @@ using std::max; #if ( defined(__GNUC__) && defined(__GNUC_MINOR__) \ && (__GNUC__ * 100 + __GNUC_MINOR__) >= 408 \ - && __cplusplus >= 201103L ) || ( _MSC_VER > 1900 ) + && __cplusplus >= 201103L ) || ( _MSC_VER >= 1900 ) #define CGAL_CAN_USE_CXX11_THREAD_LOCAL #endif diff --git a/Installation/include/CGAL/tss.h b/Installation/include/CGAL/tss.h index 4d148f8c229..0cf142fb45a 100644 --- a/Installation/include/CGAL/tss.h +++ b/Installation/include/CGAL/tss.h @@ -5,17 +5,65 @@ #if defined( CGAL_HAS_THREADS ) #ifdef CGAL_CAN_USE_CXX11_THREAD_LOCAL + #pragma message ( "Use keyword thread_local" ) #include #define CGAL_THREAD_LOCAL thread_local #else #ifdef BOOST_MSVC #include + #pragma message ("Use __declspec( thread )" ) #define CGAL_THREAD_LOCAL __declspec( thread ) #else + #pragma message ("Use thread_local from boost") + #define CGAL_USE_BOOST_THREAD #include #define CGAL_THREAD_LOCAL thread_local #endif #endif + +#ifdef CGAL_USE_BOOST_THREAD + +#define CGAL_THREAD_LOCAL_DECLARE(TYPE, VAR) static boost::thread_specific_ptr VAR##_ptr + +#define CGAL_THREAD_LOCAL_DECLARE_PTR(TYPE, VAR) static boost::thread_specific_ptr VAR + +#define CGAL_THREAD_LOCAL_IS_UNINITIALIZED(X) X.get() == NULL + +#define CGAL_THREAD_LOCAL_INITIALIZE_PTR(VAR, VAL) if(VAR.get() == NULL) {VAR.reset(VAL);} + +#define CGAL_THREAD_LOCAL_INITIALIZE(TYPE, VAR, VAL) if(VAR##_ptr.get() == NULL) {VAR##_ptr.reset(new TYPE(VAL));} + +#define CGAL_THREAD_LOCAL_SET(VAR, VAL) VAR.reset(VAL) + +#define CGAL_THREAD_LOCAL_GET_PTR(VAR) VAR.get() + +#define CGAL_THREAD_LOCAL_GET(TYPE, VAR) const TYPE& VAR = * VAR##_ptr.get() + +#else + +#define CGAL_THREAD_LOCAL_DECLARE(TYPE, VAR) static CGAL_THREAD_LOCAL TYPE* VAR##_ptr = NULL + +#define CGAL_THREAD_LOCAL_DECLARE_PTR(TYPE, VAR) static CGAL_THREAD_LOCAL TYPE* VAR = NULL + +#define CGAL_THREAD_LOCAL_IS_UNINITIALIZED(X) X == NULL + +#define CGAL_THREAD_LOCAL_INITIALIZE_PTR(VAR, VAL) if(VAR == NULL) { VAR = VAL; } + +#define CGAL_THREAD_LOCAL_INITIALIZE(TYPE, VAR, VAL) if(VAR##_ptr == NULL) { VAR##_ptr = new TYPE(VAL); } + +#define CGAL_THREAD_LOCAL_SET(VAR, VAL) VAR = VAL + +#define CGAL_THREAD_LOCAL_GET_PTR(VAR) VAR + +#define CGAL_THREAD_LOCAL_GET(TYPE, VAR) const TYPE& VAR = *VAR##_ptr +#endif + +#else + +#define CGAL_THREAD_LOCAL_INITIALIZE(TYPE, VAR, VAL) static const TYPE VAR = VAL; +#define CGAL_THREAD_LOCAL_DECLARE(TYPE, VAR) +#define CGAL_THREAD_LOCAL_GET(TYPE, VAR) + #endif #endif // CGAL_TSS_H diff --git a/Modular_arithmetic/include/CGAL/Modular_arithmetic/Residue_type.h b/Modular_arithmetic/include/CGAL/Modular_arithmetic/Residue_type.h index 36cfe593a52..67d9ed60531 100644 --- a/Modular_arithmetic/include/CGAL/Modular_arithmetic/Residue_type.h +++ b/Modular_arithmetic/include/CGAL/Modular_arithmetic/Residue_type.h @@ -64,7 +64,7 @@ private: CGAL_EXPORT static const double CST_CUT; #ifdef CGAL_HAS_THREADS -#ifdef BOOST_MSVC +#ifndef CGAL_USE_BOOST_THREAD CGAL_EXPORT CGAL_THREAD_LOCAL static int prime_int; CGAL_EXPORT CGAL_THREAD_LOCAL static double prime; CGAL_EXPORT CGAL_THREAD_LOCAL static double prime_inv; @@ -207,7 +207,7 @@ public: set_current_prime(int p){ int old_prime = get_prime_int(); #ifdef CGAL_HAS_THREADS -#ifdef BOOST_MSVC +#ifndef CGAL_USE_BOOST_THREAD prime_int = p; prime = double(p); prime_inv = 1.0 / prime; diff --git a/Modular_arithmetic/src/CGAL/Residue_type.cpp b/Modular_arithmetic/src/CGAL/Residue_type.cpp index 24f37bf1307..46661899786 100644 --- a/Modular_arithmetic/src/CGAL/Residue_type.cpp +++ b/Modular_arithmetic/src/CGAL/Residue_type.cpp @@ -22,7 +22,7 @@ namespace CGAL{ #ifdef CGAL_HAS_THREADS -#ifdef BOOST_MSVC +#ifndef CGAL_USE_BOOST_THREAD CGAL_THREAD_LOCAL int Residue::prime_int = 67111067; CGAL_THREAD_LOCAL double Residue::prime = 67111067.0; CGAL_THREAD_LOCAL double Residue::prime_inv = 1490067204.5640400859667452463541; diff --git a/Triangulation_2/include/CGAL/Delaunay_triangulation_2.h b/Triangulation_2/include/CGAL/Delaunay_triangulation_2.h index efeb008810a..57f31a977f1 100644 --- a/Triangulation_2/include/CGAL/Delaunay_triangulation_2.h +++ b/Triangulation_2/include/CGAL/Delaunay_triangulation_2.h @@ -1053,44 +1053,40 @@ remove_and_give_new_faces(Vertex_handle v, OutputItFaces fit) afi++) *fit++ = afi; } else { - #ifdef CGAL_HAS_THREADS - #ifdef BOOST_MSVC - CGAL_THREAD_LOCAL static int maxd = 30; +# ifdef CGAL_HAS_THREADS +# ifdef CGAL_USE_BOOST_THREAD + static boost::thread_specific_ptr< int > maxd_ptr; + CGAL_THREAD_LOCAL_DECLARE_PTR(std::vector >, f_ptr); + CGAL_THREAD_LOCAL_DECLARE_PTR(std::vector >, i_ptr); + CGAL_THREAD_LOCAL_DECLARE_PTR(std::vector >, w_ptr); + if (CGAL_THREAD_LOCAL_IS_UNINITIALIZED(f_ptr)) { + maxd_ptr.reset(new int(30)); + CGAL_THREAD_LOCAL_SET(f_ptr, new std::vector(*maxd_ptr)); + CGAL_THREAD_LOCAL_SET(i_ptr, new std::vector(*maxd_ptr)); + CGAL_THREAD_LOCAL_SET(w_ptr, new std::vector(*maxd_ptr)); + } + int& maxd=*maxd_ptr; +# else + CGAL_THREAD_LOCAL static int maxd = 30; - CGAL_THREAD_LOCAL static std::vector* f_ptr; - CGAL_THREAD_LOCAL static std::vector* i_ptr; - CGAL_THREAD_LOCAL static std::vector* w_ptr; - if (f_ptr == NULL) { - f_ptr = new std::vector(maxd); - i_ptr = new std::vector(maxd); - w_ptr = new std::vector(maxd); - } - std::vector& f=*f_ptr; - std::vector& i=*i_ptr; - std::vector& w=*w_ptr; - #else - - static boost::thread_specific_ptr< int > maxd_ptr; - static boost::thread_specific_ptr< std::vector > f_ptr; - static boost::thread_specific_ptr< std::vector > i_ptr; - static boost::thread_specific_ptr< std::vector > w_ptr; - if (maxd_ptr.get() == NULL) { - maxd_ptr.reset(new int(30)); - f_ptr.reset(new std::vector(*maxd_ptr)); - i_ptr.reset(new std::vector(*maxd_ptr)); - w_ptr.reset(new std::vector(*maxd_ptr)); - } - int& maxd=*maxd_ptr; - std::vector& f=*f_ptr; - std::vector& i=*i_ptr; - std::vector& w=*w_ptr; -#endif - #else - static int maxd=30; - static std::vector f(maxd); - static std::vector i(maxd); - static std::vector w(maxd); - #endif + CGAL_THREAD_LOCAL_DECLARE_PTR(std::vector >, f_ptr); + CGAL_THREAD_LOCAL_DECLARE_PTR(std::vector >, i_ptr); + CGAL_THREAD_LOCAL_DECLARE_PTR(std::vector >, w_ptr); + if (CGAL_THREAD_LOCAL_IS_UNINITIALIZED(f_ptr)) { + CGAL_THREAD_LOCAL_SET(f_ptr, new std::vector(*maxd_ptr)); + CGAL_THREAD_LOCAL_SET(i_ptr, new std::vector(*maxd_ptr)); + CGAL_THREAD_LOCAL_SET(w_ptr, new std::vector(*maxd_ptr)); + } +# endif + std::vector& f=*f_ptr; + std::vector& i=*i_ptr; + std::vector& w=*w_ptr; +# else + static int maxd=30; + static std::vector f(maxd); + static std::vector i(maxd); + static std::vector w(maxd); +# endif int d; remove_degree_init(v,f,w,i,d,maxd); remove_degree_triangulate(v,f,w,i,d); @@ -1115,7 +1111,7 @@ remove(Vertex_handle v) if ( this->dimension() <= 1) { Triangulation::remove(v); return; } #ifdef CGAL_HAS_THREADS - #ifdef BOOST_MSVC + #ifndef CGAL_USE_BOOST_THREAD CGAL_THREAD_LOCAL static int maxd = 30; CGAL_THREAD_LOCAL static std::vector* f_ptr; @@ -2295,7 +2291,7 @@ move_if_no_collision(Vertex_handle v, const Point &p) { { int d; #ifdef CGAL_HAS_THREADS - #ifdef BOOST_MSVC + #ifndef CGAL_USE_BOOST_THREAD CGAL_THREAD_LOCAL static int maxd = 30; CGAL_THREAD_LOCAL static std::vector* f_ptr; @@ -2546,7 +2542,7 @@ move_if_no_collision_and_give_new_faces(Vertex_handle v, { #ifdef CGAL_HAS_THREADS - #ifdef BOOST_MSVC + #ifndef CGAL_USE_BOOST_THREAD CGAL_THREAD_LOCAL static int maxd = 30; CGAL_THREAD_LOCAL static std::vector* f_ptr;