Make static variable thread local

This commit is contained in:
Andreas Fabri 2016-11-02 15:01:46 +01:00
parent 1c400420ce
commit 13806e86f2
2 changed files with 4 additions and 13 deletions

View File

@ -183,12 +183,13 @@ bool operator == ( Random const& random2) const;
\ingroup PkgGenerators \ingroup PkgGenerators
The global function `get_default_random()` returns the default random The global function `get_default_random()` returns the default random
numbers generator used for the generator functions and classes. numbers generator used for the generator functions and classes.
The returned generator is thread local.
*/ */
Random &get_default_random(); Random &get_default_random();
/*! /*!
\ingroup PkgGenerators \ingroup PkgGenerators
\deprecated The variable `default_random` is the default random \deprecated The variable `default_random` was the default random
numbers generator used for the generator functions and numbers generator used for the generator functions and
classes. Deprecated. Use `get_default_random()` instead. classes. Deprecated. Use `get_default_random()` instead.
*/ */

View File

@ -28,6 +28,7 @@
#include <string> #include <string>
#include <utility> #include <utility>
#include <CGAL/basic.h> #include <CGAL/basic.h>
#include <CGAL/tss.h>
#if defined(BOOST_MSVC) #if defined(BOOST_MSVC)
# pragma warning(push) # pragma warning(push)
@ -228,11 +229,9 @@ public:
boost::rand48 rng; boost::rand48 rng;
}; };
#ifdef CGAL_HEADER_ONLY
inline Random& get_default_random() inline Random& get_default_random()
{ {
static Random default_random; CGAL_STATIC_THREAD_LOCAL_VARIABLE_0(Random, default_random);
return default_random; return default_random;
} }
@ -240,16 +239,7 @@ inline Random& get_default_random()
namespace { CGAL_DEPRECATED_UNUSED CGAL::Random& default_random = get_default_random(); } namespace { CGAL_DEPRECATED_UNUSED CGAL::Random& default_random = get_default_random(); }
#endif // CGAL_NO_DEPRECATED_CODE #endif // CGAL_NO_DEPRECATED_CODE
#else // CGAL_HEADER_ONLY
// Global variables
// ================
CGAL_EXPORT extern Random default_random;
inline Random& get_default_random()
{ return default_random; }
#endif // CGAL_HEADER_ONLY
} //namespace CGAL } //namespace CGAL