remove pre-C++11 threadsafe static emulation (#641)

This commit is contained in:
Arvid Norberg 2016-04-25 08:38:48 -04:00
parent b5ecfa4f91
commit bbf411800a
2 changed files with 0 additions and 36 deletions

View File

@ -595,16 +595,6 @@ int snprintf(char* buf, int len, char const* fmt, ...)
#endif
#endif
// whether function-local static variables are thread safe. In c++11 and later
// they are (except msvc)
#ifndef TORRENT_THREADSAFE_STATIC
#if __cplusplus < 199711L || (defined _MSC_VER && _MSC_VER <= 1800)
#define TORRENT_THREADSAFE_STATIC 0
#else
#define TORRENT_THREADSAFE_STATIC 1
#endif
#endif
#ifndef TORRENT_USE_I2P
#define TORRENT_USE_I2P 1
#endif

View File

@ -42,10 +42,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#if !TORRENT_THREADSAFE_STATIC
#include "libtorrent/thread.hpp"
#endif
namespace libtorrent
{
using boost::random::random_device;
@ -63,33 +59,11 @@ namespace libtorrent
#else
#if !TORRENT_THREADSAFE_STATIC
// because local statics are not atomic pre c++11
// do it manually, probably at a higher cost
namespace
{
static mutex random_device_mutex;
static random_device* dev = NULL;
static mt19937* rnd = NULL;
}
#endif
boost::uint32_t random()
{
#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);
#else
mutex::scoped_lock l(random_device_mutex);
if (dev == NULL)
{
dev = new random_device();
rnd = new mt19937((*dev)());
}
return uniform_int_distribution<boost::uint32_t>(0, UINT_MAX)(*rnd);
#endif
}
#endif // TORRENT_BUILD_SIMULATOR