From a6c646346d625839002d6716e6f80bc8963e0ba5 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 3 Sep 2015 17:22:43 +0200 Subject: [PATCH 01/24] no thread local storage in Triangulation_data_structure_3 --- .../include/CGAL/Triangulation_data_structure_3.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/Triangulation_3/include/CGAL/Triangulation_data_structure_3.h b/Triangulation_3/include/CGAL/Triangulation_data_structure_3.h index 41d79ac6f98..fbdd537dd6a 100644 --- a/Triangulation_3/include/CGAL/Triangulation_data_structure_3.h +++ b/Triangulation_3/include/CGAL/Triangulation_data_structure_3.h @@ -51,14 +51,6 @@ #include #include -#ifdef CGAL_HAS_THREADS -# ifdef CGAL_LINKED_WITH_TBB -# include -# else -# include -# endif -#endif - #ifdef CGAL_LINKED_WITH_TBB # include #endif From 52e5f3a521d4ee0ade3866b9037d2653fb36ecb3 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 4 Sep 2015 08:38:55 +0200 Subject: [PATCH 02/24] Add a wrapper for the very basic mutex locking we make use of --- Installation/include/CGAL/mutex.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Installation/include/CGAL/mutex.h diff --git a/Installation/include/CGAL/mutex.h b/Installation/include/CGAL/mutex.h new file mode 100644 index 00000000000..0dbcdfed9f6 --- /dev/null +++ b/Installation/include/CGAL/mutex.h @@ -0,0 +1,18 @@ +#ifndef CGAL_MUTEX_H +#define CGAL_MUTEX_H + +#include + +#ifdef BOOST_MSVC +#include +#define CGAL_MUTEX std::mutex +#define CGAL_SCOPED_LOCK(M) std::unique_lock scoped_lock(M) + +#else +#include +#define CGAL_MUTEX boost::mutex +#define CGAL_SCOPED_LOCK(M) boost::mutex::scoped_lock scoped_lock(M) + +#endif + +#endif // CGAL_MUTEX_H From c7fbc5abca15c4be0ad9707227318c10d23b6146 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 4 Sep 2015 08:41:58 +0200 Subject: [PATCH 03/24] Quick hack for using VC++ thread local storage (using #ifdef BOOST_MSVC) --- Filtered_kernel/include/CGAL/Lazy.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Filtered_kernel/include/CGAL/Lazy.h b/Filtered_kernel/include/CGAL/Lazy.h index 8bcd623637f..4251b748d64 100644 --- a/Filtered_kernel/include/CGAL/Lazy.h +++ b/Filtered_kernel/include/CGAL/Lazy.h @@ -34,7 +34,7 @@ #include #include -#ifdef CGAL_HAS_THREADS +#if defined(CGAL_HAS_THREADS) && ! defined(BOOST_MSVC) # include #endif @@ -788,11 +788,20 @@ private: static const Self & zero() { #ifdef CGAL_HAS_THREADS +#if BOOST_MSVC + __declspec( thread ) 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(); return z; From 547be5cd2aa4855ddfb38a857588c9e9baa18113 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 4 Sep 2015 08:42:34 +0200 Subject: [PATCH 04/24] Use wrapper for the very basic mutex locking --- AABB_tree/include/CGAL/AABB_tree.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/AABB_tree/include/CGAL/AABB_tree.h b/AABB_tree/include/CGAL/AABB_tree.h index 9e1cba315e6..d605c02d4e9 100644 --- a/AABB_tree/include/CGAL/AABB_tree.h +++ b/AABB_tree/include/CGAL/AABB_tree.h @@ -31,7 +31,7 @@ #include #ifdef CGAL_HAS_THREADS -#include +#include #endif /// \file AABB_tree.h @@ -500,7 +500,7 @@ public: { #ifdef CGAL_HAS_THREADS //this ensures that this is done once at a time - boost::mutex::scoped_lock scoped_lock(kd_tree_mutex); + CGAL_SCOPED_LOCK(kd_tree_mutex); #endif clear_search_tree(); return accelerate_distance_queries_impl(first,beyond); @@ -599,8 +599,8 @@ public: // single root node Node* m_p_root_node; #ifdef CGAL_HAS_THREADS - mutable boost::mutex internal_tree_mutex;//mutex used to protect const calls inducing build() - mutable boost::mutex kd_tree_mutex;//mutex used to protect calls to accelerate_distance_queries + mutable CGAL_MUTEX internal_tree_mutex;//mutex used to protect const calls inducing build() + mutable CGAL_MUTEX kd_tree_mutex;//mutex used to protect calls to accelerate_distance_queries #endif const Node* root_node() const { @@ -608,7 +608,7 @@ public: if(m_need_build){ #ifdef CGAL_HAS_THREADS //this ensures that build() will be called once - boost::mutex::scoped_lock scoped_lock(internal_tree_mutex); + CGAL_SCOPED_LOCK(internal_tree_mutex); if(m_need_build) #endif const_cast< AABB_tree* >(this)->build(); @@ -1046,7 +1046,7 @@ public: if(m_primitives.empty()) return true; #ifdef CGAL_HAS_THREADS //this ensures that this function will be done once - boost::mutex::scoped_lock scoped_lock(kd_tree_mutex); + CGAL_SCOPED_LOCK(kd_tree_mutex); #endif //we only redo computation only if needed From c3ad989c9fc1ffe75b168e8b8de99b906e4fa04e Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 4 Sep 2015 09:46:51 +0200 Subject: [PATCH 05/24] Use wrapper for the very basic mutex locking --- .../CGAL/Minkowski_sum_2/AABB_tree_with_join.h | 12 ++++++------ Spatial_searching/include/CGAL/Kd_tree.h | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Minkowski_sum_2/include/CGAL/Minkowski_sum_2/AABB_tree_with_join.h b/Minkowski_sum_2/include/CGAL/Minkowski_sum_2/AABB_tree_with_join.h index fe1c8c74187..b524a97aecd 100644 --- a/Minkowski_sum_2/include/CGAL/Minkowski_sum_2/AABB_tree_with_join.h +++ b/Minkowski_sum_2/include/CGAL/Minkowski_sum_2/AABB_tree_with_join.h @@ -31,7 +31,7 @@ #include #ifdef CGAL_HAS_THREADS -#include +#include #endif /// \file AABB_tree.h @@ -506,7 +506,7 @@ public: { #ifdef CGAL_HAS_THREADS //this ensures that this is done once at a time - boost::mutex::scoped_lock scoped_lock(kd_tree_mutex); + CGAL_SCOPED_LOCK(kd_tree_mutex); #endif clear_search_tree(); return accelerate_distance_queries_impl(first,beyond); @@ -623,8 +623,8 @@ public: // single root node Node* m_p_root_node; #ifdef CGAL_HAS_THREADS - mutable boost::mutex internal_tree_mutex;//mutex used to protect const calls inducing build() - mutable boost::mutex kd_tree_mutex;//mutex used to protect calls to accelerate_distance_queries + mutable CGAL_MUTEX internal_tree_mutex;//mutex used to protect const calls inducing build() + mutable CGAL_MUTEX kd_tree_mutex;//mutex used to protect calls to accelerate_distance_queries #endif const Node* root_node() const { @@ -632,7 +632,7 @@ public: if(m_need_build){ #ifdef CGAL_HAS_THREADS //this ensures that build() will be called once - boost::mutex::scoped_lock scoped_lock(internal_tree_mutex); + CGAL_SCOPED_LOCK(internal_tree_mutex); if(m_need_build) #endif const_cast< AABB_tree_with_join* >(this)->build(); @@ -1070,7 +1070,7 @@ public: if(m_primitives.empty()) return true; #ifdef CGAL_HAS_THREADS //this ensures that this function will be done once - boost::mutex::scoped_lock scoped_lock(kd_tree_mutex); + CGAL_SCOPED_LOCK(kd_tree_mutex); #endif //we only redo computation only if needed diff --git a/Spatial_searching/include/CGAL/Kd_tree.h b/Spatial_searching/include/CGAL/Kd_tree.h index 81cc9224f6f..84f8d41f15a 100644 --- a/Spatial_searching/include/CGAL/Kd_tree.h +++ b/Spatial_searching/include/CGAL/Kd_tree.h @@ -34,7 +34,7 @@ #include #ifdef CGAL_HAS_THREADS -#include +#include #endif namespace CGAL { @@ -99,7 +99,7 @@ private: #ifdef CGAL_HAS_THREADS - mutable boost::mutex building_mutex;//mutex used to protect const calls inducing build() + mutable CGAL_MUTEX building_mutex;//mutex used to protect const calls inducing build() #endif bool built_; @@ -283,7 +283,7 @@ private: void const_build() const { #ifdef CGAL_HAS_THREADS //this ensure that build() will be called once - boost::mutex::scoped_lock scoped_lock(building_mutex); + CGAL_SCOPED_LOCK(building_mutex); if(!is_built()) #endif const_cast(this)->build(); //THIS IS NOT THREADSAFE From bc5272495ba3b5a0251cf401a5b2bd36fd15cded Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 4 Sep 2015 11:50:54 +0200 Subject: [PATCH 06/24] For MSVC we no longer require boost thread and system --- Installation/cmake/modules/CGAL_SetupBoost.cmake | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Installation/cmake/modules/CGAL_SetupBoost.cmake b/Installation/cmake/modules/CGAL_SetupBoost.cmake index 1dd3b7cce74..3f42868df79 100644 --- a/Installation/cmake/modules/CGAL_SetupBoost.cmake +++ b/Installation/cmake/modules/CGAL_SetupBoost.cmake @@ -3,7 +3,12 @@ if ( NOT CGAL_Boost_Setup ) include(CGAL_TweakFindBoost) # In the documentation, we say we require Boost-1.48, but technically we # require 1.39. Some packages may require more recent versions, though. - find_package( Boost 1.39 REQUIRED thread system ) + + if ( MSVC ) + find_package( Boost 1.39 REQUIRED ) + else() + find_package( Boost 1.39 REQUIRED thread system ) + endif() if(Boost_FOUND) if(DEFINED Boost_DIR AND NOT Boost_DIR) From 220651bc88c0c94dc64497ffe03bde4f585f59d3 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 4 Sep 2015 18:09:50 +0200 Subject: [PATCH 07/24] Use CGAL_THREAD_LOCAL as thread_local only comes with VC201 --- Filtered_kernel/include/CGAL/Lazy.h | 7 +- Installation/include/CGAL/mutex.h | 5 +- Installation/include/CGAL/tss.h | 15 ++++ .../CGAL/Modular_arithmetic/Residue_type.h | 29 ++++++-- Modular_arithmetic/src/CGAL/Residue_type.cpp | 8 ++- Number_types/include/CGAL/GMP/Gmpfi_type.h | 23 +++++- .../include/CGAL/Polynomial/Polynomial_type.h | 24 ++++--- .../include/CGAL/Delaunay_triangulation_2.h | 72 ++++++++++++++++++- 8 files changed, 154 insertions(+), 29 deletions(-) create mode 100644 Installation/include/CGAL/tss.h diff --git a/Filtered_kernel/include/CGAL/Lazy.h b/Filtered_kernel/include/CGAL/Lazy.h index 4251b748d64..4daa536683c 100644 --- a/Filtered_kernel/include/CGAL/Lazy.h +++ b/Filtered_kernel/include/CGAL/Lazy.h @@ -33,10 +33,7 @@ #include #include #include - -#if defined(CGAL_HAS_THREADS) && ! defined(BOOST_MSVC) -# include -#endif +#include #include #include @@ -789,7 +786,7 @@ private: { #ifdef CGAL_HAS_THREADS #if BOOST_MSVC - __declspec( thread ) static Self* z = NULL; + CGAL_THREAD_LOCAL static Self* z = NULL; if(z == NULL){ z = new Self(new Lazy_rep_0()); } diff --git a/Installation/include/CGAL/mutex.h b/Installation/include/CGAL/mutex.h index 0dbcdfed9f6..009bf1fa288 100644 --- a/Installation/include/CGAL/mutex.h +++ b/Installation/include/CGAL/mutex.h @@ -3,16 +3,15 @@ #include +#ifdef CGAL_HAS_THREADS #ifdef BOOST_MSVC #include #define CGAL_MUTEX std::mutex #define CGAL_SCOPED_LOCK(M) std::unique_lock scoped_lock(M) - #else #include #define CGAL_MUTEX boost::mutex #define CGAL_SCOPED_LOCK(M) boost::mutex::scoped_lock scoped_lock(M) - #endif - +#endif #endif // CGAL_MUTEX_H diff --git a/Installation/include/CGAL/tss.h b/Installation/include/CGAL/tss.h new file mode 100644 index 00000000000..fa14d291f60 --- /dev/null +++ b/Installation/include/CGAL/tss.h @@ -0,0 +1,15 @@ +#ifndef CGAL_TSS_H +#define CGAL_TSS_H + +#include + +#ifdef CGAL_HAS_THREADS +#ifdef BOOST_MSVC +#include +#define CGAL_THREAD_LOCAL __declspec( thread ) +#else +# include +#define CGAL_THREAD_LOCAL thread_local +#endif +#endif +#endif // CGAL_MUTEX_H diff --git a/Modular_arithmetic/include/CGAL/Modular_arithmetic/Residue_type.h b/Modular_arithmetic/include/CGAL/Modular_arithmetic/Residue_type.h index 18f05e7a6fd..36cfe593a52 100644 --- a/Modular_arithmetic/include/CGAL/Modular_arithmetic/Residue_type.h +++ b/Modular_arithmetic/include/CGAL/Modular_arithmetic/Residue_type.h @@ -22,16 +22,17 @@ #define CGAL_RESIDUE_TYPE_H #include +#include #include + #include -#ifdef CGAL_HAS_THREADS -# include -#endif namespace CGAL { + struct TT {int i;}; + class Residue; Residue operator + (const Residue&); @@ -63,6 +64,14 @@ private: CGAL_EXPORT static const double CST_CUT; #ifdef CGAL_HAS_THREADS +#ifdef BOOST_MSVC + 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; + static int get_prime_int(){ return prime_int;} + static double get_prime() { return prime;} + static double get_prime_inv(){ return prime_inv;} +#else CGAL_EXPORT static boost::thread_specific_ptr prime_int_; CGAL_EXPORT static boost::thread_specific_ptr prime_; CGAL_EXPORT static boost::thread_specific_ptr prime_inv_; @@ -93,10 +102,12 @@ private: init_class_for_thread(); return *prime_inv_.get(); } +#endif // ifdef BOOST_MSVC + #else - CGAL_EXPORT static int prime_int; - CGAL_EXPORT static double prime; - CGAL_EXPORT static double prime_inv; + CGAL_EXPORT static int prime_int; + CGAL_EXPORT static double prime; + CGAL_EXPORT static double prime_inv; static int get_prime_int(){ return prime_int;} static double get_prime() { return prime;} static double get_prime_inv(){ return prime_inv;} @@ -196,9 +207,15 @@ public: set_current_prime(int p){ int old_prime = get_prime_int(); #ifdef CGAL_HAS_THREADS +#ifdef BOOST_MSVC + prime_int = p; + prime = double(p); + prime_inv = 1.0 / prime; +#else *prime_int_.get() = p; *prime_.get() = double(p); *prime_inv_.get() = 1.0/double(p); +#endif #else prime_int = p; prime = double(p); diff --git a/Modular_arithmetic/src/CGAL/Residue_type.cpp b/Modular_arithmetic/src/CGAL/Residue_type.cpp index e221b51dc3e..24f37bf1307 100644 --- a/Modular_arithmetic/src/CGAL/Residue_type.cpp +++ b/Modular_arithmetic/src/CGAL/Residue_type.cpp @@ -22,13 +22,19 @@ namespace CGAL{ #ifdef CGAL_HAS_THREADS +#ifdef BOOST_MSVC +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; +#else boost::thread_specific_ptr Residue::prime_int_; boost::thread_specific_ptr Residue::prime_; boost::thread_specific_ptr Residue::prime_inv_; +#endif #else int Residue::prime_int = 67111067; double Residue::prime = 67111067.0; -double Residue::prime_inv =1/67111067.0; +double Residue::prime_inv = 1/67111067.0; #endif diff --git a/Number_types/include/CGAL/GMP/Gmpfi_type.h b/Number_types/include/CGAL/GMP/Gmpfi_type.h index bb23d9b48dd..37453897c3c 100644 --- a/Number_types/include/CGAL/GMP/Gmpfi_type.h +++ b/Number_types/include/CGAL/GMP/Gmpfi_type.h @@ -26,9 +26,8 @@ #include #include #include -#ifdef CGAL_HAS_THREADS -# include -#endif +#include + #include #include @@ -81,7 +80,11 @@ Uncertain operator==(const Gmpfi&,const Gmpq&); // the default precision is a variable local to each thread in multithreaded // environments, or a global variable otherwise #ifdef CGAL_HAS_THREADS +#ifdef BOOST_MSVC + static CGAL_THREAD_LOCAL Gmpfi_default_precision_; +#else static boost::thread_specific_ptr Gmpfi_default_precision_; +#endif #else static mp_prec_t Gmpfi_default_precision=CGAL_GMPFI_DEFAULT_PRECISION; #endif @@ -403,18 +406,28 @@ CGAL_GMPFI_CONSTRUCTOR_FROM_SCALAR(Gmpz); #ifdef CGAL_HAS_THREADS inline void Gmpfi::init_precision_for_thread(){ +#ifdef BOOST_MSVC + Gmpfi_default_precision_ = new mp_prec_t(CGAL_GMPFI_DEFAULT_PRECISION); +#else CGAL_precondition(Gmpfi_default_precision_.get()==NULL); Gmpfi_default_precision_.reset( new mp_prec_t(CGAL_GMPFI_DEFAULT_PRECISION)); +#endif } #endif inline Gmpfi::Precision_type Gmpfi::get_default_precision(){ #ifdef CGAL_HAS_THREADS +#ifdef BOOST_MSVC + if(Gmpfi_default_precision_==NULL) + Gmpfi::init_precision_for_thread(); + return *Gmpfi_default_precision_; +#else if(Gmpfi_default_precision_.get()==NULL) Gmpfi::init_precision_for_thread(); return *Gmpfi_default_precision_.get(); +#endif #else return Gmpfi_default_precision; #endif @@ -425,7 +438,11 @@ Gmpfi::Precision_type Gmpfi::set_default_precision(Gmpfi::Precision_type prec){ Gmpfi::Precision_type old_prec=Gmpfi::get_default_precision(); CGAL_assertion(prec>=MPFR_PREC_MIN&&prec<=MPFR_PREC_MAX); #ifdef CGAL_HAS_THREADS +#ifdef BOOST_MSVC + *Gmpfi_default_precision_ = prec; +#else *Gmpfi_default_precision_.get()=prec; +#endif #else Gmpfi_default_precision=prec; #endif diff --git a/Polynomial/include/CGAL/Polynomial/Polynomial_type.h b/Polynomial/include/CGAL/Polynomial/Polynomial_type.h index 5a9090e6a54..26a1dd1788c 100644 --- a/Polynomial/include/CGAL/Polynomial/Polynomial_type.h +++ b/Polynomial/include/CGAL/Polynomial/Polynomial_type.h @@ -46,10 +46,7 @@ typename CGAL::internal::Innermost_coefficient_type::Type , 2>::Type #include #include - -#ifdef CGAL_HAS_THREADS -# include -#endif +#include namespace CGAL { @@ -268,11 +265,20 @@ protected: // private: static Self& get_default_instance(){ - #ifdef CGAL_HAS_THREADS - static boost::thread_specific_ptr< Self > safe_x_ptr; - if (safe_x_ptr.get() == NULL) - safe_x_ptr.reset(new Self(0)); - return *safe_x_ptr.get(); + #ifdef CGAL_HAS_THREADS + #if BOOST_MSVC + CGAL_THREAD_LOCAL static Self* safe_x_ptr = NULL; + if(safe_x_ptr == NULL){ + safe_x_ptr = new Self(0); + } + return *safe_x_ptr; + #else + static boost::thread_specific_ptr< Self > safe_x_ptr; + if (safe_x_ptr.get() == NULL){ + safe_x_ptr.reset(new Self(0)); + } + return *safe_x_ptr.get(); + #endif #else static Self x = Self(0); return x; diff --git a/Triangulation_2/include/CGAL/Delaunay_triangulation_2.h b/Triangulation_2/include/CGAL/Delaunay_triangulation_2.h index 1e1e3d1354c..efeb008810a 100644 --- a/Triangulation_2/include/CGAL/Delaunay_triangulation_2.h +++ b/Triangulation_2/include/CGAL/Delaunay_triangulation_2.h @@ -31,7 +31,7 @@ #ifndef CGAL_TRIANGULATION_2_DONT_INSERT_RANGE_OF_POINTS_WITH_INFO #include #include - +#include #include #include @@ -1053,7 +1053,23 @@ remove_and_give_new_faces(Vertex_handle v, OutputItFaces fit) afi++) *fit++ = afi; } else { - #ifdef CGAL_HAS_THREADS + #ifdef CGAL_HAS_THREADS + #ifdef BOOST_MSVC + 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; @@ -1068,6 +1084,7 @@ remove_and_give_new_faces(Vertex_handle v, OutputItFaces fit) 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); @@ -1098,6 +1115,22 @@ remove(Vertex_handle v) if ( this->dimension() <= 1) { Triangulation::remove(v); return; } #ifdef CGAL_HAS_THREADS + #ifdef BOOST_MSVC + 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; @@ -1112,6 +1145,7 @@ remove(Vertex_handle v) 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); @@ -2261,6 +2295,22 @@ move_if_no_collision(Vertex_handle v, const Point &p) { { int d; #ifdef CGAL_HAS_THREADS + #ifdef BOOST_MSVC + 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; @@ -2275,6 +2325,7 @@ move_if_no_collision(Vertex_handle v, const Point &p) { 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); @@ -2495,6 +2546,22 @@ move_if_no_collision_and_give_new_faces(Vertex_handle v, { #ifdef CGAL_HAS_THREADS + #ifdef BOOST_MSVC + 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; @@ -2509,6 +2576,7 @@ move_if_no_collision_and_give_new_faces(Vertex_handle v, 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); From 9427e1d3aada4c42ee2a87890ebeca6f882457d4 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 7 Sep 2015 16:11:29 +0200 Subject: [PATCH 08/24] Fix a benchmark. Calling n times finite_vertices_begin() is an O(n^2) algorithm --- .../benchmark/Triangulation_2/Delaunay_remove.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Triangulation_2/benchmark/Triangulation_2/Delaunay_remove.cpp b/Triangulation_2/benchmark/Triangulation_2/Delaunay_remove.cpp index 0d95e4893ac..dc8b7ea2c0b 100644 --- a/Triangulation_2/benchmark/Triangulation_2/Delaunay_remove.cpp +++ b/Triangulation_2/benchmark/Triangulation_2/Delaunay_remove.cpp @@ -3,6 +3,8 @@ #include #include +#include +#include #include #include @@ -11,11 +13,12 @@ typedef CGAL::Exact_predicates_inexact_constructions_kernel K; typedef CGAL::Delaunay_triangulation_2 Delaunay; +typedef Delaunay::Finite_vertices_iterator FVI; +typedef Delaunay::Vertex_handle Vertex_handle; typedef K::Point_2 Point; typedef CGAL::Creator_uniform_2 Creator; - int main(int argc, char **argv) { int n=1000000; @@ -34,10 +37,14 @@ int main(int argc, char **argv) double res=0; for (int r=0;r vertices; + for(FVI fvi = delaunay.finite_vertices_begin(); fvi != delaunay.finite_vertices_end();++fvi){ + vertices.push_back(fvi); + } CGAL::Timer t; t.start(); - for (int k=0;k Date: Mon, 7 Sep 2015 16:16:04 +0200 Subject: [PATCH 09/24] cleanup of accidentally added #include --- Triangulation_2/benchmark/Triangulation_2/Delaunay_remove.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/Triangulation_2/benchmark/Triangulation_2/Delaunay_remove.cpp b/Triangulation_2/benchmark/Triangulation_2/Delaunay_remove.cpp index dc8b7ea2c0b..5d3ef4595e9 100644 --- a/Triangulation_2/benchmark/Triangulation_2/Delaunay_remove.cpp +++ b/Triangulation_2/benchmark/Triangulation_2/Delaunay_remove.cpp @@ -3,9 +3,6 @@ #include #include -#include -#include - #include #include #include From 434e66a0f1184f4bb316e2f4c9862de6a1fe8183 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 10 Sep 2015 12:44:52 +0200 Subject: [PATCH 10/24] move detection of that the keyword threadlocal can be used from Mpzf.h to config.h --- Installation/include/CGAL/config.h | 6 ++++++ Number_types/include/CGAL/Mpzf.h | 5 ----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Installation/include/CGAL/config.h b/Installation/include/CGAL/config.h index 47bbad9024d..c98862540f7 100644 --- a/Installation/include/CGAL/config.h +++ b/Installation/include/CGAL/config.h @@ -418,6 +418,12 @@ using std::max; # endif #endif +#if defined(__GNUC__) && defined(__GNUC_MINOR__) \ + && (__GNUC__ * 100 + __GNUC_MINOR__) >= 408 \ + && __cplusplus >= 201103L +#define CGAL_CAN_USE_CXX11_THREAD_LOCAL +#endif + // Support for LEDA with threads // Not that, if CGAL_HAS_THREADS is defined, and you want to use LEDA, // you must link with a version of LEDA libraries that support threads. diff --git a/Number_types/include/CGAL/Mpzf.h b/Number_types/include/CGAL/Mpzf.h index 661c96a78a8..37f5a0d22e6 100644 --- a/Number_types/include/CGAL/Mpzf.h +++ b/Number_types/include/CGAL/Mpzf.h @@ -108,11 +108,6 @@ CGAL_CLANG_PUSH_AND_IGNORE_UNUSED_LOCAL_TYPEDEF // int to bool performance #endif -#if defined(__GNUC__) && defined(__GNUC_MINOR__) \ - && (__GNUC__ * 100 + __GNUC_MINOR__) >= 408 \ - && __cplusplus >= 201103L -#define CGAL_CAN_USE_CXX11_THREAD_LOCAL -#endif /* #ifdef CGAL_MPZF_NO_USE_CACHE From aa649eccc93b52cda172fea35eadb1730e392da8 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 11 Sep 2015 08:58:32 +0200 Subject: [PATCH 11/24] bug fix --- Installation/include/CGAL/config.h | 6 +++--- Installation/include/CGAL/tss.h | 24 +++++++++++++++--------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Installation/include/CGAL/config.h b/Installation/include/CGAL/config.h index c98862540f7..d96d3a5477a 100644 --- a/Installation/include/CGAL/config.h +++ b/Installation/include/CGAL/config.h @@ -418,9 +418,9 @@ using std::max; # endif #endif -#if defined(__GNUC__) && defined(__GNUC_MINOR__) \ - && (__GNUC__ * 100 + __GNUC_MINOR__) >= 408 \ - && __cplusplus >= 201103L +#if ( defined(__GNUC__) && defined(__GNUC_MINOR__) \ + && (__GNUC__ * 100 + __GNUC_MINOR__) >= 408 \ + && __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 fa14d291f60..4d148f8c229 100644 --- a/Installation/include/CGAL/tss.h +++ b/Installation/include/CGAL/tss.h @@ -3,13 +3,19 @@ #include -#ifdef CGAL_HAS_THREADS -#ifdef BOOST_MSVC -#include -#define CGAL_THREAD_LOCAL __declspec( thread ) -#else -# include -#define CGAL_THREAD_LOCAL thread_local +#if defined( CGAL_HAS_THREADS ) + #ifdef CGAL_CAN_USE_CXX11_THREAD_LOCAL + #include + #define CGAL_THREAD_LOCAL thread_local + #else + #ifdef BOOST_MSVC + #include + #define CGAL_THREAD_LOCAL __declspec( thread ) + #else + #include + #define CGAL_THREAD_LOCAL thread_local + #endif + #endif #endif -#endif -#endif // CGAL_MUTEX_H + +#endif // CGAL_TSS_H From a14cf913e90da5c2ef49eee75ab38dd0b8bbe403 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 11 Sep 2015 14:54:11 +0200 Subject: [PATCH 12/24] WIP: In Lazy.h we now have a single macro for boost and c++11 thread --- Filtered_kernel/include/CGAL/Lazy.h | 22 +----- Installation/include/CGAL/config.h | 2 +- Installation/include/CGAL/tss.h | 48 ++++++++++++ .../CGAL/Modular_arithmetic/Residue_type.h | 4 +- Modular_arithmetic/src/CGAL/Residue_type.cpp | 2 +- .../include/CGAL/Delaunay_triangulation_2.h | 76 +++++++++---------- 6 files changed, 92 insertions(+), 62 deletions(-) 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; From ea612e96456357587f394a40861ce00b2cb6c723 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 11 Sep 2015 18:01:51 +0200 Subject: [PATCH 13/24] Improved macros to avoid #if #else where we want to use TLS The Residue.cpp file still needs simplification --- Installation/include/CGAL/tss.h | 50 ++++-- .../CGAL/Modular_arithmetic/Residue_type.h | 77 ++++----- Modular_arithmetic/src/CGAL/Residue_type.cpp | 6 +- .../include/CGAL/Delaunay_triangulation_2.h | 150 +----------------- .../CGAL/Delaunay_triangulation_2_tls.h | 26 +++ 5 files changed, 104 insertions(+), 205 deletions(-) create mode 100644 Triangulation_2/include/CGAL/Delaunay_triangulation_2_tls.h diff --git a/Installation/include/CGAL/tss.h b/Installation/include/CGAL/tss.h index 0cf142fb45a..7cc16e5615e 100644 --- a/Installation/include/CGAL/tss.h +++ b/Installation/include/CGAL/tss.h @@ -5,16 +5,16 @@ #if defined( CGAL_HAS_THREADS ) #ifdef CGAL_CAN_USE_CXX11_THREAD_LOCAL - #pragma message ( "Use keyword 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 )" ) + // #pragma message ("Use __declspec( thread )" ) #define CGAL_THREAD_LOCAL __declspec( thread ) #else - #pragma message ("Use thread_local from boost") + // #pragma message ("Use thread_local from boost") #define CGAL_USE_BOOST_THREAD #include #define CGAL_THREAD_LOCAL thread_local @@ -25,37 +25,60 @@ #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_DECLARE_POD(TYPE, VAR,VAL) static boost::thread_specific_ptr VAR##_ptr -#define CGAL_THREAD_LOCAL_IS_UNINITIALIZED(X) X.get() == NULL +#define CGAL_THREAD_LOCAL_DECLARE_POD2(TYPE, VAR) static boost::thread_specific_ptr VAR##_ptr + +#define CGAL_THREAD_LOCAL_IS_UNINITIALIZED(VAR) VAR##_ptr.get() == NULL + +#define CGAL_THREAD_LOCAL_IS_UNINITIALIZED_POD(VAR) VAR##_ptr.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_SET(VAR, VAL) VAR##_ptr.reset(VAL) + +#define CGAL_THREAD_LOCAL_SET_POD(TYPE,VAR, VAL) VAR##_ptr.reset(new TYPE(VAL)) + +#define CGAL_THREAD_LOCAL_ASSIGN_POD(VAR, VAL) * VAR##_ptr = VAL #define CGAL_THREAD_LOCAL_GET_PTR(VAR) VAR.get() -#define CGAL_THREAD_LOCAL_GET(TYPE, VAR) const TYPE& VAR = * VAR##_ptr.get() +#define CGAL_THREAD_LOCAL_GET(TYPE, VAR) TYPE& VAR = * VAR##_ptr.get() + +#define CGAL_THREAD_LOCAL_GET_POD(TYPE, VAR) 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_DECLARE_POD(TYPE, VAR, VAL) static CGAL_THREAD_LOCAL TYPE VAR = VAL -#define CGAL_THREAD_LOCAL_IS_UNINITIALIZED(X) X == NULL +#define CGAL_THREAD_LOCAL_DECLARE_POD2(TYPE, VAR) static CGAL_THREAD_LOCAL TYPE VAR + +#define CGAL_THREAD_LOCAL_IS_UNINITIALIZED(VAR) VAR##_ptr == NULL + +#define CGAL_THREAD_LOCAL_IS_UNINITIALIZED_POD(VAR) true #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_SET(VAR, VAL) VAR##_ptr = VAL + +#define CGAL_THREAD_LOCAL_SET_POD(TYPE, VAR, VAL) + +#define CGAL_THREAD_LOCAL_ASSIGN_POD(VAR, VAL) VAR = VAL #define CGAL_THREAD_LOCAL_GET_PTR(VAR) VAR -#define CGAL_THREAD_LOCAL_GET(TYPE, VAR) const TYPE& VAR = *VAR##_ptr +#define CGAL_THREAD_LOCAL_GET(TYPE, VAR) TYPE& VAR = *VAR##_ptr + +#define CGAL_THREAD_LOCAL_GET_POD(TYPE, VAR) #endif #else @@ -64,6 +87,11 @@ #define CGAL_THREAD_LOCAL_DECLARE(TYPE, VAR) #define CGAL_THREAD_LOCAL_GET(TYPE, VAR) +#define CGAL_THREAD_LOCAL_DECLARE_POD(TYPE, VAR, VAL) static TYPE VAR = VAL +#define CGAL_THREAD_LOCAL_IS_UNINITIALIZED_POD(VAR) true +#define CGAL_THREAD_LOCAL_SET_POD(TYPE, VAR, VAL) +#define CGAL_THREAD_LOCAL_ASSIGN_POD(VAR, VAL) VAR = VAL +#define CGAL_THREAD_LOCAL_GET_POD(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 67d9ed60531..b759706a171 100644 --- a/Modular_arithmetic/include/CGAL/Modular_arithmetic/Residue_type.h +++ b/Modular_arithmetic/include/CGAL/Modular_arithmetic/Residue_type.h @@ -63,55 +63,51 @@ public: private: CGAL_EXPORT static const double CST_CUT; -#ifdef CGAL_HAS_THREADS -#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; + + CGAL_EXPORT CGAL_THREAD_LOCAL_DECLARE_POD2(int, prime_int); + CGAL_EXPORT CGAL_THREAD_LOCAL_DECLARE_POD2(double, prime); + CGAL_EXPORT CGAL_THREAD_LOCAL_DECLARE_POD2(double, prime_inv); + +#if (! defined(CGAL_USE_BOOST_THREAD)) || (! defined(CGAL_HAS_THREADS)) + static int get_prime_int(){ return prime_int;} static double get_prime() { return prime;} static double get_prime_inv(){ return prime_inv;} -#else - CGAL_EXPORT static boost::thread_specific_ptr prime_int_; - CGAL_EXPORT static boost::thread_specific_ptr prime_; - CGAL_EXPORT static boost::thread_specific_ptr prime_inv_; - +#endif + +#ifdef CGAL_USE_BOOST_THREAD static void init_class_for_thread(){ - CGAL_precondition(prime_int_.get() == NULL); - CGAL_precondition(prime_.get() == NULL); - CGAL_precondition(prime_inv_.get() == NULL); - prime_int_.reset(new int(67111067)); - prime_.reset(new double(67111067.0)); - prime_inv_.reset(new double(1.0/67111067.0)); + CGAL_precondition(CGAL_THREAD_LOCAL_IS_UNINITIALIZED_POD(prime_int)); + CGAL_precondition(CGAL_THREAD_LOCAL_IS_UNINITIALIZED_POD(prime)); + CGAL_precondition(CGAL_THREAD_LOCAL_IS_UNINITIALIZED_POD(prime_inv)); + CGAL_THREAD_LOCAL_SET_POD(int,prime_int, 67111067); + CGAL_THREAD_LOCAL_SET_POD(double,prime, 67111067.0); + CGAL_THREAD_LOCAL_SET_POD(double,prime_inv, 1.0/67111067.0); } static inline int get_prime_int(){ - if (prime_int_.get() == NULL) + if (CGAL_THREAD_LOCAL_IS_UNINITIALIZED_POD(prime_int)) init_class_for_thread(); - return *prime_int_.get(); + CGAL_THREAD_LOCAL_GET_POD(int,prime_int); + return prime_int; } static inline double get_prime(){ - if (prime_.get() == NULL) + if (CGAL_THREAD_LOCAL_IS_UNINITIALIZED_POD(prime_int)) init_class_for_thread(); - return *prime_.get(); + CGAL_THREAD_LOCAL_GET_POD(double,prime); + return prime; } static inline double get_prime_inv(){ - if (prime_inv_.get() == NULL) + if (CGAL_THREAD_LOCAL_IS_UNINITIALIZED_POD(prime_int)) init_class_for_thread(); - return *prime_inv_.get(); + CGAL_THREAD_LOCAL_GET_POD(double,prime_inv); + return prime_inv; } -#endif // ifdef BOOST_MSVC +#endif // ifdef CGAL_USE_BOOST_THREAD + -#else - CGAL_EXPORT static int prime_int; - CGAL_EXPORT static double prime; - CGAL_EXPORT static double prime_inv; - static int get_prime_int(){ return prime_int;} - static double get_prime() { return prime;} - static double get_prime_inv(){ return prime_inv;} -#endif /* Quick integer rounding, valid if a<2^51. for double */ static inline @@ -206,21 +202,10 @@ public: static int set_current_prime(int p){ int old_prime = get_prime_int(); -#ifdef CGAL_HAS_THREADS -#ifndef CGAL_USE_BOOST_THREAD - prime_int = p; - prime = double(p); - prime_inv = 1.0 / prime; -#else - *prime_int_.get() = p; - *prime_.get() = double(p); - *prime_inv_.get() = 1.0/double(p); -#endif -#else - prime_int = p; - prime = double(p); - prime_inv = 1.0 / prime; -#endif + CGAL_THREAD_LOCAL_ASSIGN_POD(prime_int,p); + CGAL_THREAD_LOCAL_ASSIGN_POD(prime,double(p)); + CGAL_THREAD_LOCAL_ASSIGN_POD(prime_inv, 1.0 / double(p)); + return old_prime; } diff --git a/Modular_arithmetic/src/CGAL/Residue_type.cpp b/Modular_arithmetic/src/CGAL/Residue_type.cpp index 46661899786..ab1545999b5 100644 --- a/Modular_arithmetic/src/CGAL/Residue_type.cpp +++ b/Modular_arithmetic/src/CGAL/Residue_type.cpp @@ -27,9 +27,9 @@ 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; #else -boost::thread_specific_ptr Residue::prime_int_; -boost::thread_specific_ptr Residue::prime_; -boost::thread_specific_ptr Residue::prime_inv_; +boost::thread_specific_ptr Residue::prime_int_ptr; +boost::thread_specific_ptr Residue::prime_ptr; +boost::thread_specific_ptr Residue::prime_inv_ptr; #endif #else int Residue::prime_int = 67111067; diff --git a/Triangulation_2/include/CGAL/Delaunay_triangulation_2.h b/Triangulation_2/include/CGAL/Delaunay_triangulation_2.h index 57f31a977f1..dc61d7b3fc1 100644 --- a/Triangulation_2/include/CGAL/Delaunay_triangulation_2.h +++ b/Triangulation_2/include/CGAL/Delaunay_triangulation_2.h @@ -1053,40 +1053,9 @@ remove_and_give_new_faces(Vertex_handle v, OutputItFaces fit) afi++) *fit++ = afi; } else { -# 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_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 +#include "Delaunay_triangulation_2_tls.h.h" + int d; remove_degree_init(v,f,w,i,d,maxd); remove_degree_triangulate(v,f,w,i,d); @@ -1110,44 +1079,8 @@ remove(Vertex_handle v) if ( this->dimension() <= 1) { Triangulation::remove(v); return; } - #ifdef CGAL_HAS_THREADS - #ifndef CGAL_USE_BOOST_THREAD - CGAL_THREAD_LOCAL static int maxd = 30; +#include "Delaunay_triangulation_2_tls.h.h" - 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 remove_degree_init(v,f,w,i,d,maxd); if (d == 0) return; // dim is going down remove_degree_triangulate(v,f,w,i,d); @@ -2290,44 +2223,8 @@ move_if_no_collision(Vertex_handle v, const Point &p) { { int d; - #ifdef CGAL_HAS_THREADS - #ifndef CGAL_USE_BOOST_THREAD - CGAL_THREAD_LOCAL static int maxd = 30; +#include "Delaunay_triangulation_2_tls.h.h" - 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 remove_degree_init(v,f,w,i,d,maxd); remove_degree_triangulate(v,f,w,i,d); } @@ -2541,44 +2438,7 @@ move_if_no_collision_and_give_new_faces(Vertex_handle v, { - #ifdef CGAL_HAS_THREADS - #ifndef CGAL_USE_BOOST_THREAD - 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 +#include "Delaunay_triangulation_2_tls.h.h" int d; remove_degree_init(v,f,w,i,d,maxd); remove_degree_triangulate(v,f,w,i,d); diff --git a/Triangulation_2/include/CGAL/Delaunay_triangulation_2_tls.h b/Triangulation_2/include/CGAL/Delaunay_triangulation_2_tls.h new file mode 100644 index 00000000000..ddacaeab38f --- /dev/null +++ b/Triangulation_2/include/CGAL/Delaunay_triangulation_2_tls.h @@ -0,0 +1,26 @@ + + + CGAL_THREAD_LOCAL_DECLARE_POD(int, maxd,30); + if (CGAL_THREAD_LOCAL_IS_UNINITIALIZED_POD(maxd)) { + CGAL_THREAD_LOCAL_SET_POD(int, maxd,30); + } + CGAL_THREAD_LOCAL_GET_POD(int,maxd); + + +# ifdef CGAL_HAS_THREADS + CGAL_THREAD_LOCAL_DECLARE(std::vector , f); + CGAL_THREAD_LOCAL_DECLARE(std::vector , i); + CGAL_THREAD_LOCAL_DECLARE(std::vector , w); + if (CGAL_THREAD_LOCAL_IS_UNINITIALIZED(f)) { + CGAL_THREAD_LOCAL_SET(f, new std::vector(maxd)); + CGAL_THREAD_LOCAL_SET(i, new std::vector(maxd)); + CGAL_THREAD_LOCAL_SET(w, new std::vector(maxd)); + } + CGAL_THREAD_LOCAL_GET(std::vector, f); + CGAL_THREAD_LOCAL_GET(std::vector, i); + CGAL_THREAD_LOCAL_GET(std::vector, w); +# else + static std::vector f(maxd); + static std::vector i(maxd); + static std::vector w(maxd); +# endif From 4ba71bce359de96a102f927838fa0373e20d0bb7 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 14 Sep 2015 09:50:03 +0200 Subject: [PATCH 14/24] fix for the single threaded case --- Installation/include/CGAL/tss.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Installation/include/CGAL/tss.h b/Installation/include/CGAL/tss.h index 7cc16e5615e..22f103e19fd 100644 --- a/Installation/include/CGAL/tss.h +++ b/Installation/include/CGAL/tss.h @@ -88,6 +88,7 @@ #define CGAL_THREAD_LOCAL_GET(TYPE, VAR) #define CGAL_THREAD_LOCAL_DECLARE_POD(TYPE, VAR, VAL) static TYPE VAR = VAL +#define CGAL_THREAD_LOCAL_DECLARE_POD2(TYPE, VAR) static TYPE VAR; #define CGAL_THREAD_LOCAL_IS_UNINITIALIZED_POD(VAR) true #define CGAL_THREAD_LOCAL_SET_POD(TYPE, VAR, VAL) #define CGAL_THREAD_LOCAL_ASSIGN_POD(VAR, VAL) VAR = VAL From 0d70d7b1cecba2a71d6b23e8fc0392a73cd616ce Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 14 Sep 2015 10:17:22 +0200 Subject: [PATCH 15/24] do not write 'static' in the macro so that we can use the macro also for a definition --- Installation/include/CGAL/tss.h | 16 ++++++++-------- .../CGAL/Modular_arithmetic/Residue_type.h | 6 +++--- Modular_arithmetic/src/CGAL/Residue_type.cpp | 19 ++++--------------- .../CGAL/Delaunay_triangulation_2_tls.h | 8 ++++---- 4 files changed, 19 insertions(+), 30 deletions(-) diff --git a/Installation/include/CGAL/tss.h b/Installation/include/CGAL/tss.h index 22f103e19fd..80454df9b6e 100644 --- a/Installation/include/CGAL/tss.h +++ b/Installation/include/CGAL/tss.h @@ -23,11 +23,11 @@ #ifdef CGAL_USE_BOOST_THREAD -#define CGAL_THREAD_LOCAL_DECLARE(TYPE, VAR) static boost::thread_specific_ptr VAR##_ptr +#define CGAL_THREAD_LOCAL_DECLARE(TYPE, VAR) boost::thread_specific_ptr VAR##_ptr -#define CGAL_THREAD_LOCAL_DECLARE_POD(TYPE, VAR,VAL) static boost::thread_specific_ptr VAR##_ptr +#define CGAL_THREAD_LOCAL_DECLARE_POD(TYPE, VAR,VAL) boost::thread_specific_ptr VAR##_ptr -#define CGAL_THREAD_LOCAL_DECLARE_POD2(TYPE, VAR) static boost::thread_specific_ptr VAR##_ptr +#define CGAL_THREAD_LOCAL_DECLARE_POD2(TYPE, VAR) boost::thread_specific_ptr VAR##_ptr #define CGAL_THREAD_LOCAL_IS_UNINITIALIZED(VAR) VAR##_ptr.get() == NULL @@ -54,11 +54,11 @@ -#define CGAL_THREAD_LOCAL_DECLARE(TYPE, VAR) static CGAL_THREAD_LOCAL TYPE* VAR##_ptr = NULL +#define CGAL_THREAD_LOCAL_DECLARE(TYPE, VAR) CGAL_THREAD_LOCAL TYPE* VAR##_ptr = NULL -#define CGAL_THREAD_LOCAL_DECLARE_POD(TYPE, VAR, VAL) static CGAL_THREAD_LOCAL TYPE VAR = VAL +#define CGAL_THREAD_LOCAL_DECLARE_POD(TYPE, VAR, VAL) CGAL_THREAD_LOCAL TYPE VAR = VAL -#define CGAL_THREAD_LOCAL_DECLARE_POD2(TYPE, VAR) static CGAL_THREAD_LOCAL TYPE VAR +#define CGAL_THREAD_LOCAL_DECLARE_POD2(TYPE, VAR) CGAL_THREAD_LOCAL TYPE VAR #define CGAL_THREAD_LOCAL_IS_UNINITIALIZED(VAR) VAR##_ptr == NULL @@ -87,8 +87,8 @@ #define CGAL_THREAD_LOCAL_DECLARE(TYPE, VAR) #define CGAL_THREAD_LOCAL_GET(TYPE, VAR) -#define CGAL_THREAD_LOCAL_DECLARE_POD(TYPE, VAR, VAL) static TYPE VAR = VAL -#define CGAL_THREAD_LOCAL_DECLARE_POD2(TYPE, VAR) static TYPE VAR; +#define CGAL_THREAD_LOCAL_DECLARE_POD(TYPE, VAR, VAL) TYPE VAR = VAL +#define CGAL_THREAD_LOCAL_DECLARE_POD2(TYPE, VAR) TYPE VAR; #define CGAL_THREAD_LOCAL_IS_UNINITIALIZED_POD(VAR) true #define CGAL_THREAD_LOCAL_SET_POD(TYPE, VAR, VAL) #define CGAL_THREAD_LOCAL_ASSIGN_POD(VAR, VAL) VAR = VAL diff --git a/Modular_arithmetic/include/CGAL/Modular_arithmetic/Residue_type.h b/Modular_arithmetic/include/CGAL/Modular_arithmetic/Residue_type.h index b759706a171..4d4d42cd1ac 100644 --- a/Modular_arithmetic/include/CGAL/Modular_arithmetic/Residue_type.h +++ b/Modular_arithmetic/include/CGAL/Modular_arithmetic/Residue_type.h @@ -64,9 +64,9 @@ private: CGAL_EXPORT static const double CST_CUT; - CGAL_EXPORT CGAL_THREAD_LOCAL_DECLARE_POD2(int, prime_int); - CGAL_EXPORT CGAL_THREAD_LOCAL_DECLARE_POD2(double, prime); - CGAL_EXPORT CGAL_THREAD_LOCAL_DECLARE_POD2(double, prime_inv); + CGAL_EXPORT static CGAL_THREAD_LOCAL_DECLARE_POD2(int, prime_int); + CGAL_EXPORT static CGAL_THREAD_LOCAL_DECLARE_POD2(double, prime); + CGAL_EXPORT static CGAL_THREAD_LOCAL_DECLARE_POD2(double, prime_inv); #if (! defined(CGAL_USE_BOOST_THREAD)) || (! defined(CGAL_HAS_THREADS)) diff --git a/Modular_arithmetic/src/CGAL/Residue_type.cpp b/Modular_arithmetic/src/CGAL/Residue_type.cpp index ab1545999b5..ac8923ef36d 100644 --- a/Modular_arithmetic/src/CGAL/Residue_type.cpp +++ b/Modular_arithmetic/src/CGAL/Residue_type.cpp @@ -21,22 +21,11 @@ #include namespace CGAL{ -#ifdef CGAL_HAS_THREADS -#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; -#else -boost::thread_specific_ptr Residue::prime_int_ptr; -boost::thread_specific_ptr Residue::prime_ptr; -boost::thread_specific_ptr Residue::prime_inv_ptr; -#endif -#else -int Residue::prime_int = 67111067; -double Residue::prime = 67111067.0; -double Residue::prime_inv = 1/67111067.0; -#endif + CGAL_THREAD_LOCAL_DECLARE_POD(int, Residue::prime_int, 67111067); + CGAL_THREAD_LOCAL_DECLARE_POD(double, Residue::prime, 67111067.0); + CGAL_THREAD_LOCAL_DECLARE_POD(double, Residue::prime_inv, 1490067204.5640400859667452463541); + const double Residue::CST_CUT = std::ldexp( 3., 51 ); diff --git a/Triangulation_2/include/CGAL/Delaunay_triangulation_2_tls.h b/Triangulation_2/include/CGAL/Delaunay_triangulation_2_tls.h index ddacaeab38f..82fae2c6237 100644 --- a/Triangulation_2/include/CGAL/Delaunay_triangulation_2_tls.h +++ b/Triangulation_2/include/CGAL/Delaunay_triangulation_2_tls.h @@ -1,6 +1,6 @@ - CGAL_THREAD_LOCAL_DECLARE_POD(int, maxd,30); + static CGAL_THREAD_LOCAL_DECLARE_POD(int, maxd,30); if (CGAL_THREAD_LOCAL_IS_UNINITIALIZED_POD(maxd)) { CGAL_THREAD_LOCAL_SET_POD(int, maxd,30); } @@ -8,9 +8,9 @@ # ifdef CGAL_HAS_THREADS - CGAL_THREAD_LOCAL_DECLARE(std::vector , f); - CGAL_THREAD_LOCAL_DECLARE(std::vector , i); - CGAL_THREAD_LOCAL_DECLARE(std::vector , w); + static CGAL_THREAD_LOCAL_DECLARE(std::vector , f); + static CGAL_THREAD_LOCAL_DECLARE(std::vector , i); + static CGAL_THREAD_LOCAL_DECLARE(std::vector , w); if (CGAL_THREAD_LOCAL_IS_UNINITIALIZED(f)) { CGAL_THREAD_LOCAL_SET(f, new std::vector(maxd)); CGAL_THREAD_LOCAL_SET(i, new std::vector(maxd)); From 700f9febe769faf03b901404c68fb5455b17bc24 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 14 Sep 2015 12:15:27 +0200 Subject: [PATCH 16/24] Add 'static' --- Filtered_kernel/include/CGAL/Lazy.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Filtered_kernel/include/CGAL/Lazy.h b/Filtered_kernel/include/CGAL/Lazy.h index 55e2aa4c087..f8c2c886218 100644 --- a/Filtered_kernel/include/CGAL/Lazy.h +++ b/Filtered_kernel/include/CGAL/Lazy.h @@ -785,7 +785,7 @@ private: static const Self & zero() { Lazy_rep_0* ptr = new Lazy_rep_0(); - CGAL_THREAD_LOCAL_DECLARE(Self,z); + static CGAL_THREAD_LOCAL_DECLARE(Self,z); CGAL_THREAD_LOCAL_INITIALIZE(Self,z, ptr); CGAL_THREAD_LOCAL_GET(Self,z); return z; From 3d4a1be42998c6a68a0bc224ab281a0257ce8c2a Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 1 Oct 2015 09:47:47 +0200 Subject: [PATCH 17/24] WIP with Clement --- Filtered_kernel/include/CGAL/Lazy.h | 4 + Installation/include/CGAL/tss.h | 139 +++++++++--------- .../CGAL/Modular_arithmetic/Residue_type.h | 65 ++++---- Modular_arithmetic/src/CGAL/Residue_type.cpp | 4 - Number_types/include/CGAL/GMP/Gmpfi_type.h | 62 ++------ .../include/CGAL/Polynomial/Polynomial_type.h | 6 +- .../include/CGAL/Delaunay_triangulation_2.h | 8 +- .../CGAL/Delaunay_triangulation_2_tls.h | 27 +--- 8 files changed, 130 insertions(+), 185 deletions(-) diff --git a/Filtered_kernel/include/CGAL/Lazy.h b/Filtered_kernel/include/CGAL/Lazy.h index f8c2c886218..2c0e2a934a8 100644 --- a/Filtered_kernel/include/CGAL/Lazy.h +++ b/Filtered_kernel/include/CGAL/Lazy.h @@ -785,9 +785,13 @@ private: static const Self & zero() { Lazy_rep_0* ptr = new Lazy_rep_0(); +#if 1 + static CGAL_THREAD_LOCAL_VARIABLE(Self,z,ptr); +#else static CGAL_THREAD_LOCAL_DECLARE(Self,z); CGAL_THREAD_LOCAL_INITIALIZE(Self,z, ptr); CGAL_THREAD_LOCAL_GET(Self,z); +#endif return z; } diff --git a/Installation/include/CGAL/tss.h b/Installation/include/CGAL/tss.h index 80454df9b6e..c21f989b601 100644 --- a/Installation/include/CGAL/tss.h +++ b/Installation/include/CGAL/tss.h @@ -4,95 +4,98 @@ #include #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_CAN_USE_CXX11_THREAD_LOCAL +# pragma message ( "Use keyword thread_local" ) +# include +# define CGAL_THREAD_LOCAL thread_local +# else +# pragma message ("Use thread_local from boost") +# define CGAL_USE_BOOST_THREAD +# include +# define CGAL_THREAD_LOCAL thread_local +# endif -#ifdef CGAL_USE_BOOST_THREAD - -#define CGAL_THREAD_LOCAL_DECLARE(TYPE, VAR) boost::thread_specific_ptr VAR##_ptr - -#define CGAL_THREAD_LOCAL_DECLARE_POD(TYPE, VAR,VAL) boost::thread_specific_ptr VAR##_ptr - -#define CGAL_THREAD_LOCAL_DECLARE_POD2(TYPE, VAR) boost::thread_specific_ptr VAR##_ptr - -#define CGAL_THREAD_LOCAL_IS_UNINITIALIZED(VAR) VAR##_ptr.get() == NULL - -#define CGAL_THREAD_LOCAL_IS_UNINITIALIZED_POD(VAR) VAR##_ptr.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##_ptr.reset(VAL) - -#define CGAL_THREAD_LOCAL_SET_POD(TYPE,VAR, VAL) VAR##_ptr.reset(new TYPE(VAL)) - -#define CGAL_THREAD_LOCAL_ASSIGN_POD(VAR, VAL) * VAR##_ptr = VAL - -#define CGAL_THREAD_LOCAL_GET_PTR(VAR) VAR.get() - -#define CGAL_THREAD_LOCAL_GET(TYPE, VAR) TYPE& VAR = * VAR##_ptr.get() - -#define CGAL_THREAD_LOCAL_GET_POD(TYPE, VAR) TYPE& VAR = * VAR##_ptr.get() - -#else +# ifdef CGAL_USE_BOOST_THREAD +# define CGAL_THREAD_LOCAL_VARIABLE(TYPE, VAR,VAL) \ + boost::thread_specific_ptr VAR##_ptr; \ + if(VAR##_ptr.get() == NULL) {VAR##_ptr.reset(new TYPE(VAL));} \ + TYPE& VAR = * VAR##_ptr.get() + +# define CGAL_THREAD_LOCAL_DECLARE(TYPE, VAR) boost::thread_specific_ptr VAR##_ptr + +# define CGAL_THREAD_LOCAL_DECLARE_POD(TYPE, VAR,VAL) boost::thread_specific_ptr VAR##_ptr + +# define CGAL_THREAD_LOCAL_DECLARE_POD2(TYPE, VAR) boost::thread_specific_ptr VAR##_ptr + +# define CGAL_THREAD_LOCAL_IS_UNINITIALIZED(VAR) VAR##_ptr.get() == NULL + +# define CGAL_THREAD_LOCAL_IS_UNINITIALIZED_POD(VAR) VAR##_ptr.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##_ptr.reset(VAL) + +# define CGAL_THREAD_LOCAL_SET_POD(TYPE,VAR, VAL) VAR##_ptr.reset(new TYPE(VAL)) + +# define CGAL_THREAD_LOCAL_ASSIGN_POD(VAR, VAL) * VAR##_ptr = VAL + +# define CGAL_THREAD_LOCAL_GET_PTR(VAR) VAR.get() + +# define CGAL_THREAD_LOCAL_GET(TYPE, VAR) TYPE& VAR = * VAR##_ptr.get() + +# define CGAL_THREAD_LOCAL_GET_POD(TYPE, VAR) TYPE& VAR = * VAR##_ptr.get() + +# else + +# define CGAL_THREAD_LOCAL_VARIABLE(TYPE, VAR,VAL) \ + CGAL_THREAD_LOCAL TYPE VAR = VAL -#define CGAL_THREAD_LOCAL_DECLARE(TYPE, VAR) CGAL_THREAD_LOCAL TYPE* VAR##_ptr = NULL +# define CGAL_THREAD_LOCAL_DECLARE(TYPE, VAR) CGAL_THREAD_LOCAL TYPE* VAR##_ptr = NULL -#define CGAL_THREAD_LOCAL_DECLARE_POD(TYPE, VAR, VAL) CGAL_THREAD_LOCAL TYPE VAR = VAL +# define CGAL_THREAD_LOCAL_DECLARE_POD(TYPE, VAR, VAL) CGAL_THREAD_LOCAL TYPE VAR = VAL -#define CGAL_THREAD_LOCAL_DECLARE_POD2(TYPE, VAR) CGAL_THREAD_LOCAL TYPE VAR +# define CGAL_THREAD_LOCAL_DECLARE_POD2(TYPE, VAR) CGAL_THREAD_LOCAL TYPE VAR -#define CGAL_THREAD_LOCAL_IS_UNINITIALIZED(VAR) VAR##_ptr == NULL +# define CGAL_THREAD_LOCAL_IS_UNINITIALIZED(VAR) VAR##_ptr == NULL -#define CGAL_THREAD_LOCAL_IS_UNINITIALIZED_POD(VAR) true +# define CGAL_THREAD_LOCAL_IS_UNINITIALIZED_POD(VAR) true -#define CGAL_THREAD_LOCAL_INITIALIZE_PTR(VAR, VAL) if(VAR == NULL) { VAR = VAL; } +# 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_INITIALIZE(TYPE, VAR, VAL) if(VAR##_ptr == NULL) { VAR##_ptr = new TYPE(VAL); } -#define CGAL_THREAD_LOCAL_SET(VAR, VAL) VAR##_ptr = VAL +# define CGAL_THREAD_LOCAL_SET(VAR, VAL) VAR##_ptr = VAL -#define CGAL_THREAD_LOCAL_SET_POD(TYPE, VAR, VAL) +# define CGAL_THREAD_LOCAL_SET_POD(TYPE, VAR, VAL) -#define CGAL_THREAD_LOCAL_ASSIGN_POD(VAR, VAL) VAR = VAL +# define CGAL_THREAD_LOCAL_ASSIGN_POD(VAR, VAL) VAR = VAL -#define CGAL_THREAD_LOCAL_GET_PTR(VAR) VAR +# define CGAL_THREAD_LOCAL_GET_PTR(VAR) VAR -#define CGAL_THREAD_LOCAL_GET(TYPE, VAR) TYPE& VAR = *VAR##_ptr +# define CGAL_THREAD_LOCAL_GET(TYPE, VAR) TYPE& VAR = *VAR##_ptr -#define CGAL_THREAD_LOCAL_GET_POD(TYPE, VAR) -#endif +# define CGAL_THREAD_LOCAL_GET_POD(TYPE, VAR) +# 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) +# define CGAL_THREAD_LOCAL_VARIABLE(TYPE, VAR,VAL) TYPE VAR = VAL -#define CGAL_THREAD_LOCAL_DECLARE_POD(TYPE, VAR, VAL) TYPE VAR = VAL -#define CGAL_THREAD_LOCAL_DECLARE_POD2(TYPE, VAR) TYPE VAR; -#define CGAL_THREAD_LOCAL_IS_UNINITIALIZED_POD(VAR) true -#define CGAL_THREAD_LOCAL_SET_POD(TYPE, VAR, VAL) -#define CGAL_THREAD_LOCAL_ASSIGN_POD(VAR, VAL) VAR = VAL -#define CGAL_THREAD_LOCAL_GET_POD(TYPE, VAR) +# 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) + +# define CGAL_THREAD_LOCAL_DECLARE_POD(TYPE, VAR, VAL) TYPE VAR = VAL +# define CGAL_THREAD_LOCAL_DECLARE_POD2(TYPE, VAR) TYPE VAR; +# define CGAL_THREAD_LOCAL_IS_UNINITIALIZED_POD(VAR) true +# define CGAL_THREAD_LOCAL_SET_POD(TYPE, VAR, VAL) +# define CGAL_THREAD_LOCAL_ASSIGN_POD(VAR, VAL) VAR = VAL +# define CGAL_THREAD_LOCAL_GET_POD(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 4d4d42cd1ac..d1bf0eaca93 100644 --- a/Modular_arithmetic/include/CGAL/Modular_arithmetic/Residue_type.h +++ b/Modular_arithmetic/include/CGAL/Modular_arithmetic/Residue_type.h @@ -61,51 +61,40 @@ public: typedef Residue NT; private: - CGAL_EXPORT static const double CST_CUT; - + CGAL_EXPORT static const double CST_CUT; - CGAL_EXPORT static CGAL_THREAD_LOCAL_DECLARE_POD2(int, prime_int); - CGAL_EXPORT static CGAL_THREAD_LOCAL_DECLARE_POD2(double, prime); - CGAL_EXPORT static CGAL_THREAD_LOCAL_DECLARE_POD2(double, prime_inv); -#if (! defined(CGAL_USE_BOOST_THREAD)) || (! defined(CGAL_HAS_THREADS)) - - static int get_prime_int(){ return prime_int;} - static double get_prime() { return prime;} - static double get_prime_inv(){ return prime_inv;} -#endif - -#ifdef CGAL_USE_BOOST_THREAD - static void init_class_for_thread(){ - CGAL_precondition(CGAL_THREAD_LOCAL_IS_UNINITIALIZED_POD(prime_int)); - CGAL_precondition(CGAL_THREAD_LOCAL_IS_UNINITIALIZED_POD(prime)); - CGAL_precondition(CGAL_THREAD_LOCAL_IS_UNINITIALIZED_POD(prime_inv)); - CGAL_THREAD_LOCAL_SET_POD(int,prime_int, 67111067); - CGAL_THREAD_LOCAL_SET_POD(double,prime, 67111067.0); - CGAL_THREAD_LOCAL_SET_POD(double,prime_inv, 1.0/67111067.0); - } - - static inline int get_prime_int(){ - if (CGAL_THREAD_LOCAL_IS_UNINITIALIZED_POD(prime_int)) - init_class_for_thread(); - CGAL_THREAD_LOCAL_GET_POD(int,prime_int); + static int& prime_int_internal() + { + static CGAL_THREAD_LOCAL_VARIABLE(int, prime_int, 67111067); return prime_int; } + + static inline int get_prime_int(){ + return prime_int_internal(); + } + - static inline double get_prime(){ - if (CGAL_THREAD_LOCAL_IS_UNINITIALIZED_POD(prime_int)) - init_class_for_thread(); - CGAL_THREAD_LOCAL_GET_POD(double,prime); + static double& prime_internal() + { + static CGAL_THREAD_LOCAL_VARIABLE(double, prime, 67111067.0); return prime; } + + static inline double get_prime(){ + return prime_internal(); + } - static inline double get_prime_inv(){ - if (CGAL_THREAD_LOCAL_IS_UNINITIALIZED_POD(prime_int)) - init_class_for_thread(); - CGAL_THREAD_LOCAL_GET_POD(double,prime_inv); + static double& prime_inv_internal() + { + static CGAL_THREAD_LOCAL_VARIABLE(double, prime_inv, 1490067204.5640400859667452463541); return prime_inv; } -#endif // ifdef CGAL_USE_BOOST_THREAD + + static inline double get_prime_inv(){ + return prime_inv_internal(); + } + @@ -202,9 +191,9 @@ public: static int set_current_prime(int p){ int old_prime = get_prime_int(); - CGAL_THREAD_LOCAL_ASSIGN_POD(prime_int,p); - CGAL_THREAD_LOCAL_ASSIGN_POD(prime,double(p)); - CGAL_THREAD_LOCAL_ASSIGN_POD(prime_inv, 1.0 / double(p)); + prime_int_internal() = p; + prime_internal() = double(p); + prime_inv_internal() = 1.0 / double(p); return old_prime; } diff --git a/Modular_arithmetic/src/CGAL/Residue_type.cpp b/Modular_arithmetic/src/CGAL/Residue_type.cpp index ac8923ef36d..deb45756810 100644 --- a/Modular_arithmetic/src/CGAL/Residue_type.cpp +++ b/Modular_arithmetic/src/CGAL/Residue_type.cpp @@ -22,10 +22,6 @@ namespace CGAL{ - CGAL_THREAD_LOCAL_DECLARE_POD(int, Residue::prime_int, 67111067); - CGAL_THREAD_LOCAL_DECLARE_POD(double, Residue::prime, 67111067.0); - CGAL_THREAD_LOCAL_DECLARE_POD(double, Residue::prime_inv, 1490067204.5640400859667452463541); - const double Residue::CST_CUT = std::ldexp( 3., 51 ); diff --git a/Number_types/include/CGAL/GMP/Gmpfi_type.h b/Number_types/include/CGAL/GMP/Gmpfi_type.h index 37453897c3c..95dcc271be8 100644 --- a/Number_types/include/CGAL/GMP/Gmpfi_type.h +++ b/Number_types/include/CGAL/GMP/Gmpfi_type.h @@ -79,15 +79,8 @@ Uncertain operator==(const Gmpfi&,const Gmpq&); // the default precision is a variable local to each thread in multithreaded // environments, or a global variable otherwise -#ifdef CGAL_HAS_THREADS -#ifdef BOOST_MSVC - static CGAL_THREAD_LOCAL Gmpfi_default_precision_; -#else - static boost::thread_specific_ptr Gmpfi_default_precision_; -#endif -#else - static mp_prec_t Gmpfi_default_precision=CGAL_GMPFI_DEFAULT_PRECISION; -#endif + + class Gmpfi: boost::ordered_euclidian_ring_operators1=MPFR_PREC_MIN&&prec<=MPFR_PREC_MAX); -#ifdef CGAL_HAS_THREADS -#ifdef BOOST_MSVC - *Gmpfi_default_precision_ = prec; -#else - *Gmpfi_default_precision_.get()=prec; -#endif -#else - Gmpfi_default_precision=prec; -#endif + default_precision() = prec; + return old_prec; } diff --git a/Polynomial/include/CGAL/Polynomial/Polynomial_type.h b/Polynomial/include/CGAL/Polynomial/Polynomial_type.h index 26a1dd1788c..019c5d327c2 100644 --- a/Polynomial/include/CGAL/Polynomial/Polynomial_type.h +++ b/Polynomial/include/CGAL/Polynomial/Polynomial_type.h @@ -265,6 +265,9 @@ protected: // private: static Self& get_default_instance(){ + CGAL_THREAD_LOCAL_VARIABLE(Self, x, Self(0)); + return x; +#if 0 #ifdef CGAL_HAS_THREADS #if BOOST_MSVC CGAL_THREAD_LOCAL static Self* safe_x_ptr = NULL; @@ -282,7 +285,8 @@ private: #else static Self x = Self(0); return x; - #endif + #endif +#endif } public: diff --git a/Triangulation_2/include/CGAL/Delaunay_triangulation_2.h b/Triangulation_2/include/CGAL/Delaunay_triangulation_2.h index dc61d7b3fc1..931653b7577 100644 --- a/Triangulation_2/include/CGAL/Delaunay_triangulation_2.h +++ b/Triangulation_2/include/CGAL/Delaunay_triangulation_2.h @@ -1054,7 +1054,7 @@ remove_and_give_new_faces(Vertex_handle v, OutputItFaces fit) } else { -#include "Delaunay_triangulation_2_tls.h.h" +#include "Delaunay_triangulation_2_tls.h" int d; remove_degree_init(v,f,w,i,d,maxd); @@ -1079,7 +1079,7 @@ remove(Vertex_handle v) if ( this->dimension() <= 1) { Triangulation::remove(v); return; } -#include "Delaunay_triangulation_2_tls.h.h" +#include "Delaunay_triangulation_2_tls.h" remove_degree_init(v,f,w,i,d,maxd); if (d == 0) return; // dim is going down @@ -2223,7 +2223,7 @@ move_if_no_collision(Vertex_handle v, const Point &p) { { int d; -#include "Delaunay_triangulation_2_tls.h.h" +#include "Delaunay_triangulation_2_tls.h" remove_degree_init(v,f,w,i,d,maxd); remove_degree_triangulate(v,f,w,i,d); @@ -2438,7 +2438,7 @@ move_if_no_collision_and_give_new_faces(Vertex_handle v, { -#include "Delaunay_triangulation_2_tls.h.h" +#include "Delaunay_triangulation_2_tls.h" int d; remove_degree_init(v,f,w,i,d,maxd); remove_degree_triangulate(v,f,w,i,d); diff --git a/Triangulation_2/include/CGAL/Delaunay_triangulation_2_tls.h b/Triangulation_2/include/CGAL/Delaunay_triangulation_2_tls.h index 82fae2c6237..ed47d6cf882 100644 --- a/Triangulation_2/include/CGAL/Delaunay_triangulation_2_tls.h +++ b/Triangulation_2/include/CGAL/Delaunay_triangulation_2_tls.h @@ -1,26 +1,7 @@ - static CGAL_THREAD_LOCAL_DECLARE_POD(int, maxd,30); - if (CGAL_THREAD_LOCAL_IS_UNINITIALIZED_POD(maxd)) { - CGAL_THREAD_LOCAL_SET_POD(int, maxd,30); - } - CGAL_THREAD_LOCAL_GET_POD(int,maxd); +static CGAL_THREAD_LOCAL_VARIABLE(int, maxd,30); +static CGAL_THREAD_LOCAL_VARIABLE(std::vector , f, std::vector(maxd)); +static CGAL_THREAD_LOCAL_VARIABLE(std::vector, i, std::vector(maxd)); +static CGAL_THREAD_LOCAL_VARIABLE(std::vector, w, std::vector(maxd)); - -# ifdef CGAL_HAS_THREADS - static CGAL_THREAD_LOCAL_DECLARE(std::vector , f); - static CGAL_THREAD_LOCAL_DECLARE(std::vector , i); - static CGAL_THREAD_LOCAL_DECLARE(std::vector , w); - if (CGAL_THREAD_LOCAL_IS_UNINITIALIZED(f)) { - CGAL_THREAD_LOCAL_SET(f, new std::vector(maxd)); - CGAL_THREAD_LOCAL_SET(i, new std::vector(maxd)); - CGAL_THREAD_LOCAL_SET(w, new std::vector(maxd)); - } - CGAL_THREAD_LOCAL_GET(std::vector, f); - CGAL_THREAD_LOCAL_GET(std::vector, i); - CGAL_THREAD_LOCAL_GET(std::vector, w); -# else - static std::vector f(maxd); - static std::vector i(maxd); - static std::vector w(maxd); -# endif From 47a41ccab00814c327a1b8596a060a508e8d3393 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 1 Oct 2015 12:38:55 +0200 Subject: [PATCH 18/24] cleanup --- Filtered_kernel/include/CGAL/Lazy.h | 6 -- .../cmake/modules/CGAL_SetupBoost.cmake | 2 +- Installation/include/CGAL/tss.h | 69 +------------------ .../include/CGAL/Polynomial/Polynomial_type.h | 22 +----- 4 files changed, 4 insertions(+), 95 deletions(-) diff --git a/Filtered_kernel/include/CGAL/Lazy.h b/Filtered_kernel/include/CGAL/Lazy.h index 2c0e2a934a8..a5ad8d7065a 100644 --- a/Filtered_kernel/include/CGAL/Lazy.h +++ b/Filtered_kernel/include/CGAL/Lazy.h @@ -785,13 +785,7 @@ private: static const Self & zero() { Lazy_rep_0* ptr = new Lazy_rep_0(); -#if 1 static CGAL_THREAD_LOCAL_VARIABLE(Self,z,ptr); -#else - static CGAL_THREAD_LOCAL_DECLARE(Self,z); - CGAL_THREAD_LOCAL_INITIALIZE(Self,z, ptr); - CGAL_THREAD_LOCAL_GET(Self,z); -#endif return z; } diff --git a/Installation/cmake/modules/CGAL_SetupBoost.cmake b/Installation/cmake/modules/CGAL_SetupBoost.cmake index 3f42868df79..e424b7d7b97 100644 --- a/Installation/cmake/modules/CGAL_SetupBoost.cmake +++ b/Installation/cmake/modules/CGAL_SetupBoost.cmake @@ -4,7 +4,7 @@ if ( NOT CGAL_Boost_Setup ) # In the documentation, we say we require Boost-1.48, but technically we # require 1.39. Some packages may require more recent versions, though. - if ( MSVC ) + if ( ${MSVC_VERSION} GREATER 1800) find_package( Boost 1.39 REQUIRED ) else() find_package( Boost 1.39 REQUIRED thread system ) diff --git a/Installation/include/CGAL/tss.h b/Installation/include/CGAL/tss.h index c21f989b601..afe7219e7ff 100644 --- a/Installation/include/CGAL/tss.h +++ b/Installation/include/CGAL/tss.h @@ -6,96 +6,31 @@ #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 # pragma message ("Use thread_local from boost") # define CGAL_USE_BOOST_THREAD # include -# define CGAL_THREAD_LOCAL thread_local # endif -# ifdef CGAL_USE_BOOST_THREAD +# ifdef CGAL_USE_BOOST_THREAD # define CGAL_THREAD_LOCAL_VARIABLE(TYPE, VAR,VAL) \ boost::thread_specific_ptr VAR##_ptr; \ if(VAR##_ptr.get() == NULL) {VAR##_ptr.reset(new TYPE(VAL));} \ TYPE& VAR = * VAR##_ptr.get() -# define CGAL_THREAD_LOCAL_DECLARE(TYPE, VAR) boost::thread_specific_ptr VAR##_ptr - -# define CGAL_THREAD_LOCAL_DECLARE_POD(TYPE, VAR,VAL) boost::thread_specific_ptr VAR##_ptr - -# define CGAL_THREAD_LOCAL_DECLARE_POD2(TYPE, VAR) boost::thread_specific_ptr VAR##_ptr - -# define CGAL_THREAD_LOCAL_IS_UNINITIALIZED(VAR) VAR##_ptr.get() == NULL - -# define CGAL_THREAD_LOCAL_IS_UNINITIALIZED_POD(VAR) VAR##_ptr.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##_ptr.reset(VAL) - -# define CGAL_THREAD_LOCAL_SET_POD(TYPE,VAR, VAL) VAR##_ptr.reset(new TYPE(VAL)) - -# define CGAL_THREAD_LOCAL_ASSIGN_POD(VAR, VAL) * VAR##_ptr = VAL - -# define CGAL_THREAD_LOCAL_GET_PTR(VAR) VAR.get() - -# define CGAL_THREAD_LOCAL_GET(TYPE, VAR) TYPE& VAR = * VAR##_ptr.get() - -# define CGAL_THREAD_LOCAL_GET_POD(TYPE, VAR) TYPE& VAR = * VAR##_ptr.get() - # else # define CGAL_THREAD_LOCAL_VARIABLE(TYPE, VAR,VAL) \ - CGAL_THREAD_LOCAL TYPE VAR = VAL + thread_local TYPE VAR = VAL - -# define CGAL_THREAD_LOCAL_DECLARE(TYPE, VAR) CGAL_THREAD_LOCAL TYPE* VAR##_ptr = NULL - -# define CGAL_THREAD_LOCAL_DECLARE_POD(TYPE, VAR, VAL) CGAL_THREAD_LOCAL TYPE VAR = VAL - -# define CGAL_THREAD_LOCAL_DECLARE_POD2(TYPE, VAR) CGAL_THREAD_LOCAL TYPE VAR - -# define CGAL_THREAD_LOCAL_IS_UNINITIALIZED(VAR) VAR##_ptr == NULL - -# define CGAL_THREAD_LOCAL_IS_UNINITIALIZED_POD(VAR) true - -# 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##_ptr = VAL - -# define CGAL_THREAD_LOCAL_SET_POD(TYPE, VAR, VAL) - -# define CGAL_THREAD_LOCAL_ASSIGN_POD(VAR, VAL) VAR = VAL - -# define CGAL_THREAD_LOCAL_GET_PTR(VAR) VAR - -# define CGAL_THREAD_LOCAL_GET(TYPE, VAR) TYPE& VAR = *VAR##_ptr - -# define CGAL_THREAD_LOCAL_GET_POD(TYPE, VAR) # endif #else # define CGAL_THREAD_LOCAL_VARIABLE(TYPE, VAR,VAL) TYPE VAR = VAL -# 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) - -# define CGAL_THREAD_LOCAL_DECLARE_POD(TYPE, VAR, VAL) TYPE VAR = VAL -# define CGAL_THREAD_LOCAL_DECLARE_POD2(TYPE, VAR) TYPE VAR; -# define CGAL_THREAD_LOCAL_IS_UNINITIALIZED_POD(VAR) true -# define CGAL_THREAD_LOCAL_SET_POD(TYPE, VAR, VAL) -# define CGAL_THREAD_LOCAL_ASSIGN_POD(VAR, VAL) VAR = VAL -# define CGAL_THREAD_LOCAL_GET_POD(TYPE, VAR) #endif #endif // CGAL_TSS_H diff --git a/Polynomial/include/CGAL/Polynomial/Polynomial_type.h b/Polynomial/include/CGAL/Polynomial/Polynomial_type.h index 019c5d327c2..f83b4093e04 100644 --- a/Polynomial/include/CGAL/Polynomial/Polynomial_type.h +++ b/Polynomial/include/CGAL/Polynomial/Polynomial_type.h @@ -266,27 +266,7 @@ protected: private: static Self& get_default_instance(){ CGAL_THREAD_LOCAL_VARIABLE(Self, x, Self(0)); - return x; -#if 0 - #ifdef CGAL_HAS_THREADS - #if BOOST_MSVC - CGAL_THREAD_LOCAL static Self* safe_x_ptr = NULL; - if(safe_x_ptr == NULL){ - safe_x_ptr = new Self(0); - } - return *safe_x_ptr; - #else - static boost::thread_specific_ptr< Self > safe_x_ptr; - if (safe_x_ptr.get() == NULL){ - safe_x_ptr.reset(new Self(0)); - } - return *safe_x_ptr.get(); - #endif - #else - static Self x = Self(0); - return x; - #endif -#endif + return x; } public: From 1a083a41fb35492395864b587c44387cd39066ab Mon Sep 17 00:00:00 2001 From: Clement Jamin Date: Thu, 1 Oct 2015 14:56:12 +0200 Subject: [PATCH 19/24] Fix merge error --- .../include/CGAL/Modular_arithmetic/Residue_type.h | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/Modular_arithmetic/include/CGAL/Modular_arithmetic/Residue_type.h b/Modular_arithmetic/include/CGAL/Modular_arithmetic/Residue_type.h index 51a4498b874..860a83f2456 100644 --- a/Modular_arithmetic/include/CGAL/Modular_arithmetic/Residue_type.h +++ b/Modular_arithmetic/include/CGAL/Modular_arithmetic/Residue_type.h @@ -70,15 +70,7 @@ private: static const double& get_static_CST_CUT() { return Residue::CST_CUT; } #endif // CGAL_HEADER_ONLY - - static boost::thread_specific_ptr& get_static_prime_int_() - { return Residue::prime_int_; } - static boost::thread_specific_ptr& get_static_prime_() - { return Residue::prime_; } - static boost::thread_specific_ptr& get_static_prime_inv_() - { return Residue::prime_inv_; } -#endif // CGAL_HEADER_ONLY - + static int& prime_int_internal() { static CGAL_THREAD_LOCAL_VARIABLE(int, prime_int, 67111067); From d7c7747927d842130e3e846d0c6214aa0f43c440 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 2 Oct 2015 10:23:27 +0200 Subject: [PATCH 20/24] fix for non VC++ --- Installation/cmake/modules/CGAL_SetupBoost.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Installation/cmake/modules/CGAL_SetupBoost.cmake b/Installation/cmake/modules/CGAL_SetupBoost.cmake index e424b7d7b97..fb9f745a203 100644 --- a/Installation/cmake/modules/CGAL_SetupBoost.cmake +++ b/Installation/cmake/modules/CGAL_SetupBoost.cmake @@ -4,7 +4,7 @@ if ( NOT CGAL_Boost_Setup ) # In the documentation, we say we require Boost-1.48, but technically we # require 1.39. Some packages may require more recent versions, though. - if ( ${MSVC_VERSION} GREATER 1800) + if ( DEFINED MSVC_VERSION AND ( ${MSVC_VERSION} GREATER 1800) ) find_package( Boost 1.39 REQUIRED ) else() find_package( Boost 1.39 REQUIRED thread system ) From 1331fc6c09c69c3535a107e908e3bf1afbf4d662 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 2 Oct 2015 10:26:26 +0200 Subject: [PATCH 21/24] commnt message --- Installation/include/CGAL/tss.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Installation/include/CGAL/tss.h b/Installation/include/CGAL/tss.h index afe7219e7ff..5a9e99696e3 100644 --- a/Installation/include/CGAL/tss.h +++ b/Installation/include/CGAL/tss.h @@ -5,9 +5,9 @@ #if defined( CGAL_HAS_THREADS ) # ifdef CGAL_CAN_USE_CXX11_THREAD_LOCAL -# pragma message ( "Use keyword thread_local" ) +//# pragma message ( "Use keyword thread_local" ) # else -# pragma message ("Use thread_local from boost") +//# pragma message ("Use thread_local from boost") # define CGAL_USE_BOOST_THREAD # include # endif From bd1de66629c54e4a35b1b6fe0108394b1751f4a3 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Fri, 2 Oct 2015 10:30:36 +0200 Subject: [PATCH 22/24] Update CGAL_SetupBoost --- Installation/cmake/modules/CGAL_SetupBoost.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Installation/cmake/modules/CGAL_SetupBoost.cmake b/Installation/cmake/modules/CGAL_SetupBoost.cmake index fb9f745a203..1af372c7e4e 100644 --- a/Installation/cmake/modules/CGAL_SetupBoost.cmake +++ b/Installation/cmake/modules/CGAL_SetupBoost.cmake @@ -4,7 +4,7 @@ if ( NOT CGAL_Boost_Setup ) # In the documentation, we say we require Boost-1.48, but technically we # require 1.39. Some packages may require more recent versions, though. - if ( DEFINED MSVC_VERSION AND ( ${MSVC_VERSION} GREATER 1800) ) + if ( DEFINED MSVC_VERSION AND ( "${MSVC_VERSION}" GREATER 1800) ) find_package( Boost 1.39 REQUIRED ) else() find_package( Boost 1.39 REQUIRED thread system ) From adf615c4276385ffa8543e5bad0b230192f228e7 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 5 Oct 2015 09:42:37 +0200 Subject: [PATCH 23/24] explain in changes.html and the installation pages when Boost.Thread is no longer used --- Documentation/doc/Documentation/Installation.txt | 11 ++++++----- Installation/changes.html | 7 +++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Documentation/doc/Documentation/Installation.txt b/Documentation/doc/Documentation/Installation.txt index 121886f523b..ad84733a4ac 100644 --- a/Documentation/doc/Documentation/Installation.txt +++ b/Documentation/doc/Documentation/Installation.txt @@ -293,7 +293,7 @@ We next list the libraries and essential 3rd party software | Library | CMake Variable | Functionality | Dependencies | | :-------- | :------------- | :------------ | :----------- | -| `%CGAL` | none | Main library | \sc{Gmp}, \sc{Mpfr}, \sc{Boost} (headers), Boost.Thread and Boost.System (library) | +| `%CGAL` | none | Main library | \sc{Gmp}, \sc{Mpfr}, \sc{Boost} (headers), Boost.Thread and Boost.System (library) for compilers not supporting the keyword `threadlocal` | | `CGAL_Core` | `WITH_CGAL_Core` | The CORE library for algebraic numbers.\cgalFootnote{CGAL_Core is not part of \cgal, but a custom version of the \sc{Core} library distributed by \cgal for the user convenience and it has it's own license.} | \sc{Gmp} and \sc{Mpfr} | | `CGAL_ImageIO` | `WITH_CGAL_ImageIO` | Utilities to read and write image files | \sc{OpenGL}, \sc{zlib}, \sc{Vtk}(optional) | | `CGAL_Qt3` | `WITH_CGAL_Qt3` | `CGAL::Qt_widget` used by \sc{Qt}3-based demos | \sc{Qt}3 and \sc{OpenGL} | @@ -351,7 +351,8 @@ installed as binaries. \cgal requires the \sc{Boost} libraries. In particular the header files and the threading library (`Boost.Thread` and -`Boost.System` binaries). Version 1.48 (or higher) are needed. +`Boost.System` binaries). Version 1.48 (or higher) are needed +for compilers not supporting the keyword `threadlocal` (This is supported for g++ when using the option `-std=c++11`, and for Visual C++ starting with 2015, that is VC14). On Windows, as auto-linking is used, you also need the binaries of `Boost.Serialization` and `Boost.DateTime`, but the @@ -361,9 +362,9 @@ not depend on the DLL's of those two libraries. In \cgal some demos and examples depend on `Boost.Program_options`. In case the \sc{Boost} libraries are not installed on your system already, you -can obtain them from `http://www.boost.org/`. For Windows you can download precompiled libraries -from `http://boost.teeks99.com/`. -Since `Boost.Thread` is required, make sure to either install the precompiled +can obtain them from `http://www.boost.org/`. For Visual C++ you can download precompiled libraries +from `http://sourceforge.net/projects/boost/files/boost-binaries/`. +For Visual C++ versions prior to 2015 `Boost.Thread` is required, so make sure to either install the precompiled libraries for your compiler or build `libboost-thread` and `libboost-system`. As on Windows there is no canonical directory for where to find diff --git a/Installation/changes.html b/Installation/changes.html index 967987039dd..2b11fc472ef 100644 --- a/Installation/changes.html +++ b/Installation/changes.html @@ -119,6 +119,13 @@ and src/ directories).

Release date:

+

Installation

+
    +
  • Starting with Visual C++ 2015 we no longer require Boost.Thread + as we use the keyword threadlocal and the class mutex + from the header file . +
  • The same holds for g++ when compiling with the option -std=c++11. +
From ca54af03c2de3424efaf022530ccba5ad6029a32 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 5 Oct 2015 12:19:13 +0200 Subject: [PATCH 24/24] Use starting with Visual 2012 and g++ 4.8 with std=c++11 --- Installation/include/CGAL/config.h | 6 ++++++ Installation/include/CGAL/mutex.h | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Installation/include/CGAL/config.h b/Installation/include/CGAL/config.h index 05b2b4bb011..1409442f10b 100644 --- a/Installation/include/CGAL/config.h +++ b/Installation/include/CGAL/config.h @@ -424,6 +424,12 @@ using std::max; #define CGAL_CAN_USE_CXX11_THREAD_LOCAL #endif +#if ( defined(__GNUC__) && defined(__GNUC_MINOR__) \ + && (__GNUC__ * 100 + __GNUC_MINOR__) >= 408 \ + && __cplusplus >= 201103L ) || ( _MSC_VER >= 1700 ) +#define CGAL_CAN_USE_CXX11_MUTEX +#endif + // Support for LEDA with threads // Not that, if CGAL_HAS_THREADS is defined, and you want to use LEDA, // you must link with a version of LEDA libraries that support threads. diff --git a/Installation/include/CGAL/mutex.h b/Installation/include/CGAL/mutex.h index 009bf1fa288..0491970d485 100644 --- a/Installation/include/CGAL/mutex.h +++ b/Installation/include/CGAL/mutex.h @@ -4,7 +4,7 @@ #include #ifdef CGAL_HAS_THREADS -#ifdef BOOST_MSVC +#ifdef CGAL_CAN_USE_CXX11_MUTEX #include #define CGAL_MUTEX std::mutex #define CGAL_SCOPED_LOCK(M) std::unique_lock scoped_lock(M)