forked from premiere/premiere-libtorrent
remove pre-C++11 threadsafe static emulation (#641)
This commit is contained in:
parent
b5ecfa4f91
commit
bbf411800a
|
@ -595,16 +595,6 @@ int snprintf(char* buf, int len, char const* fmt, ...)
|
||||||
#endif
|
#endif
|
||||||
#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
|
#ifndef TORRENT_USE_I2P
|
||||||
#define TORRENT_USE_I2P 1
|
#define TORRENT_USE_I2P 1
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -42,10 +42,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#include "libtorrent/aux_/disable_warnings_pop.hpp"
|
#include "libtorrent/aux_/disable_warnings_pop.hpp"
|
||||||
|
|
||||||
#if !TORRENT_THREADSAFE_STATIC
|
|
||||||
#include "libtorrent/thread.hpp"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace libtorrent
|
namespace libtorrent
|
||||||
{
|
{
|
||||||
using boost::random::random_device;
|
using boost::random::random_device;
|
||||||
|
@ -63,33 +59,11 @@ namespace libtorrent
|
||||||
|
|
||||||
#else
|
#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()
|
boost::uint32_t random()
|
||||||
{
|
{
|
||||||
#if TORRENT_THREADSAFE_STATIC
|
|
||||||
static random_device dev;
|
static random_device dev;
|
||||||
static mt19937 random_engine(dev());
|
static mt19937 random_engine(dev());
|
||||||
return uniform_int_distribution<boost::uint32_t>(0, UINT_MAX)(random_engine);
|
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
|
#endif // TORRENT_BUILD_SIMULATOR
|
||||||
|
|
Loading…
Reference in New Issue