Use CGAL_THREAD_LOCAL as thread_local only comes with VC201

This commit is contained in:
Andreas Fabri 2015-09-04 18:09:50 +02:00
parent bc5272495b
commit 220651bc88
8 changed files with 154 additions and 29 deletions

View File

@ -33,10 +33,7 @@
#include <CGAL/Bbox_3.h>
#include <vector>
#include <CGAL/Default.h>
#if defined(CGAL_HAS_THREADS) && ! defined(BOOST_MSVC)
# include <boost/thread/tss.hpp>
#endif
#include<CGAL/tss.h>
#include <boost/optional.hpp>
#include <boost/variant.hpp>
@ -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<AT, ET, E2A>());
}

View File

@ -3,16 +3,15 @@
#include <CGAL/config.h>
#ifdef CGAL_HAS_THREADS
#ifdef BOOST_MSVC
#include <mutex>
#define CGAL_MUTEX std::mutex
#define CGAL_SCOPED_LOCK(M) std::unique_lock<std::mutex> scoped_lock(M)
#else
#include <boost/thread/mutex.hpp>
#define CGAL_MUTEX boost::mutex
#define CGAL_SCOPED_LOCK(M) boost::mutex::scoped_lock scoped_lock(M)
#endif
#endif
#endif // CGAL_MUTEX_H

View File

@ -0,0 +1,15 @@
#ifndef CGAL_TSS_H
#define CGAL_TSS_H
#include <CGAL/config.h>
#ifdef CGAL_HAS_THREADS
#ifdef BOOST_MSVC
#include <thread>
#define CGAL_THREAD_LOCAL __declspec( thread )
#else
# include <boost/thread/tss.hpp>
#define CGAL_THREAD_LOCAL thread_local
#endif
#endif
#endif // CGAL_MUTEX_H

View File

@ -22,16 +22,17 @@
#define CGAL_RESIDUE_TYPE_H
#include <CGAL/basic.h>
#include <CGAL/tss.h>
#include <cfloat>
#include <boost/operators.hpp>
#ifdef CGAL_HAS_THREADS
# include <boost/thread/tss.hpp>
#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<int> prime_int_;
CGAL_EXPORT static boost::thread_specific_ptr<double> prime_;
CGAL_EXPORT static boost::thread_specific_ptr<double> 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);

View File

@ -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<int> Residue::prime_int_;
boost::thread_specific_ptr<double> Residue::prime_;
boost::thread_specific_ptr<double> 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

View File

@ -26,9 +26,8 @@
#include <mpfi.h>
#include <boost/operators.hpp>
#include <CGAL/Uncertain.h>
#ifdef CGAL_HAS_THREADS
# include <boost/thread/tss.hpp>
#endif
#include <CGAL/tss.h>
#include <limits>
#include <algorithm>
@ -81,7 +80,11 @@ Uncertain<bool> 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<mp_prec_t> 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

View File

@ -46,10 +46,7 @@ typename CGAL::internal::Innermost_coefficient_type<T>::Type , 2>::Type
#include <CGAL/Polynomial/misc.h>
#include <CGAL/use.h>
#ifdef CGAL_HAS_THREADS
# include <boost/thread/tss.hpp>
#endif
#include <CGAL/tss.h>
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;

View File

@ -31,7 +31,7 @@
#ifndef CGAL_TRIANGULATION_2_DONT_INSERT_RANGE_OF_POINTS_WITH_INFO
#include <CGAL/Spatial_sort_traits_adapter_2.h>
#include <CGAL/internal/info_check.h>
#include <CGAL/tss.h>
#include <boost/iterator/zip_iterator.hpp>
#include <boost/mpl/and.hpp>
@ -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<Face_handle>* f_ptr;
CGAL_THREAD_LOCAL static std::vector<int>* i_ptr;
CGAL_THREAD_LOCAL static std::vector<Vertex_handle>* w_ptr;
if (f_ptr == NULL) {
f_ptr = new std::vector<Face_handle>(maxd);
i_ptr = new std::vector<int>(maxd);
w_ptr = new std::vector<Vertex_handle>(maxd);
}
std::vector<Face_handle>& f=*f_ptr;
std::vector<int>& i=*i_ptr;
std::vector<Vertex_handle>& w=*w_ptr;
#else
static boost::thread_specific_ptr< int > maxd_ptr;
static boost::thread_specific_ptr< std::vector<Face_handle> > f_ptr;
static boost::thread_specific_ptr< std::vector<int> > i_ptr;
@ -1068,6 +1084,7 @@ remove_and_give_new_faces(Vertex_handle v, OutputItFaces fit)
std::vector<Face_handle>& f=*f_ptr;
std::vector<int>& i=*i_ptr;
std::vector<Vertex_handle>& w=*w_ptr;
#endif
#else
static int maxd=30;
static std::vector<Face_handle> 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<Face_handle>* f_ptr;
CGAL_THREAD_LOCAL static std::vector<int>* i_ptr;
CGAL_THREAD_LOCAL static std::vector<Vertex_handle>* w_ptr;
if (f_ptr == NULL) {
f_ptr = new std::vector<Face_handle>(maxd);
i_ptr = new std::vector<int>(maxd);
w_ptr = new std::vector<Vertex_handle>(maxd);
}
std::vector<Face_handle>& f=*f_ptr;
std::vector<int>& i=*i_ptr;
std::vector<Vertex_handle>& w=*w_ptr;
#else
static boost::thread_specific_ptr< int > maxd_ptr;
static boost::thread_specific_ptr< std::vector<Face_handle> > f_ptr;
static boost::thread_specific_ptr< std::vector<int> > i_ptr;
@ -1112,6 +1145,7 @@ remove(Vertex_handle v)
std::vector<Face_handle>& f=*f_ptr;
std::vector<int>& i=*i_ptr;
std::vector<Vertex_handle>& w=*w_ptr;
#endif
#else
static int maxd=30;
static std::vector<Face_handle> 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<Face_handle>* f_ptr;
CGAL_THREAD_LOCAL static std::vector<int>* i_ptr;
CGAL_THREAD_LOCAL static std::vector<Vertex_handle>* w_ptr;
if (f_ptr == NULL) {
f_ptr = new std::vector<Face_handle>(maxd);
i_ptr = new std::vector<int>(maxd);
w_ptr = new std::vector<Vertex_handle>(maxd);
}
std::vector<Face_handle>& f=*f_ptr;
std::vector<int>& i=*i_ptr;
std::vector<Vertex_handle>& w=*w_ptr;
#else
static boost::thread_specific_ptr< int > maxd_ptr;
static boost::thread_specific_ptr< std::vector<Face_handle> > f_ptr;
static boost::thread_specific_ptr< std::vector<int> > i_ptr;
@ -2275,6 +2325,7 @@ move_if_no_collision(Vertex_handle v, const Point &p) {
std::vector<Face_handle>& f=*f_ptr;
std::vector<int>& i=*i_ptr;
std::vector<Vertex_handle>& w=*w_ptr;
#endif
#else
static int maxd=30;
static std::vector<Face_handle> 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<Face_handle>* f_ptr;
CGAL_THREAD_LOCAL static std::vector<int>* i_ptr;
CGAL_THREAD_LOCAL static std::vector<Vertex_handle>* w_ptr;
if (f_ptr == NULL) {
f_ptr = new std::vector<Face_handle>(maxd);
i_ptr = new std::vector<int>(maxd);
w_ptr = new std::vector<Vertex_handle>(maxd);
}
std::vector<Face_handle>& f=*f_ptr;
std::vector<int>& i=*i_ptr;
std::vector<Vertex_handle>& w=*w_ptr;
#else
static boost::thread_specific_ptr< int > maxd_ptr;
static boost::thread_specific_ptr< std::vector<Face_handle> > f_ptr;
static boost::thread_specific_ptr< std::vector<int> > i_ptr;
@ -2509,6 +2576,7 @@ move_if_no_collision_and_give_new_faces(Vertex_handle v,
std::vector<Face_handle>& f=*f_ptr;
std::vector<int>& i=*i_ptr;
std::vector<Vertex_handle>& w=*w_ptr;
#endif
#else
static int maxd=30;
static std::vector<Face_handle> f(maxd);