relying on local statics being threadsafe still does not seem safe on msvc

This commit is contained in:
Arvid Norberg 2015-01-18 16:52:39 +00:00
parent 609b5eb4ba
commit a7bec127f1
2 changed files with 14 additions and 2 deletions

View File

@ -528,6 +528,14 @@ int snprintf(char* buf, int len, char const* fmt, ...)
#endif
#endif
#ifndef TORRENT_THREADSAFE_STATIC
#if __cplusplus < 199711L || _MSC_VER < 1800
#define TORRENT_THREADSAFE_STATIC 0
#else
#define TORRENT_THREADSAFE_STATIC 1
#endif
#endif
// if set to true, piece picker will use less RAM
// but only support up to ~260000 pieces in a torrent
#ifndef TORRENT_COMPACT_PICKER

View File

@ -37,13 +37,17 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int_distribution.hpp>
#if !TORRENT_THREADSAFE_STATIC
#include "libtorrent/thread.hpp"
#endif
namespace libtorrent
{
using boost::random::random_device;
using boost::random::mt19937;
using boost::random::uniform_int_distribution;
#if __cplusplus < 199711L
#if !TORRENT_THREADSAFE_STATIC
// because local statics are not atomic pre c++11
// do it manually, probably at a higher cost
namespace
@ -56,7 +60,7 @@ namespace libtorrent
boost::uint32_t random()
{
#if __cplusplus >= 199711L
#if TORRENT_THREADSAFE_STATIC
static random_device dev;
static mt19937 random_engine(dev());
return uniform_int_distribution<boost::uint32_t>(0, UINT_MAX)(random_engine);