fix c++98 support

This commit is contained in:
Arvid Norberg 2015-01-18 02:06:18 +00:00
parent 0afea4bb3e
commit de616b29c5
2 changed files with 27 additions and 5 deletions

View File

@ -39,15 +39,37 @@ POSSIBILITY OF SUCH DAMAGE.
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()
{
using boost::random::random_device;
using boost::random::mt19937;
using boost::random::uniform_int_distribution;
#if __cplusplus >= 199711L
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
}
}

View File

@ -151,7 +151,7 @@ int run_upnp_test(char const* root_filename, char const* router_model, char cons
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")
, user_agent, &callback, &log_callback, false);
upnp_handler->start();