fix c++98 support
This commit is contained in:
parent
0afea4bb3e
commit
de616b29c5
|
@ -39,15 +39,37 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
namespace libtorrent
|
namespace libtorrent
|
||||||
{
|
{
|
||||||
|
using boost::random::random_device;
|
||||||
|
using boost::random::mt19937;
|
||||||
|
using boost::random::uniform_int_distribution;
|
||||||
|
|
||||||
|
#if __cplusplus < 199711L
|
||||||
|
// 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()
|
||||||
{
|
{
|
||||||
using boost::random::random_device;
|
#if __cplusplus >= 199711L
|
||||||
using boost::random::mt19937;
|
|
||||||
using boost::random::uniform_int_distribution;
|
|
||||||
|
|
||||||
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -151,7 +151,7 @@ int run_upnp_test(char const* root_filename, char const* router_model, char cons
|
||||||
|
|
||||||
std::string user_agent = "test agent";
|
std::string user_agent = "test agent";
|
||||||
|
|
||||||
boost::shared_ptr<upnp> upnp_handler = boost::make_shared<upnp>(ios
|
boost::shared_ptr<upnp> upnp_handler = boost::make_shared<upnp>(boost::ref(ios)
|
||||||
, address_v4::from_string("127.0.0.1")
|
, address_v4::from_string("127.0.0.1")
|
||||||
, user_agent, &callback, &log_callback, false);
|
, user_agent, &callback, &log_callback, false);
|
||||||
upnp_handler->start();
|
upnp_handler->start();
|
||||||
|
|
Loading…
Reference in New Issue