mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-01-10 14:58:05 +00:00
update time.cpp/ptime from upstream (r10083) trying to fix non-monotonic time issues with win32.
still one assert from disk_io_thread must be commented out to avoid aborting.
This commit is contained in:
parent
c9d6b2d0af
commit
7240fee4e9
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
Copyright (c) 2009-2012, Arvid Norberg
|
Copyright (c) 2009-2014, Arvid Norberg
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
@ -57,14 +57,21 @@ namespace libtorrent
|
|||||||
// libtorrent time_duration type
|
// libtorrent time_duration type
|
||||||
struct TORRENT_EXPORT time_duration
|
struct TORRENT_EXPORT time_duration
|
||||||
{
|
{
|
||||||
|
// hidden
|
||||||
time_duration() {}
|
time_duration() {}
|
||||||
|
|
||||||
|
// all operators have the same semantics as a 64 bit signed integer
|
||||||
time_duration operator/(int rhs) const { return time_duration(diff / rhs); }
|
time_duration operator/(int rhs) const { return time_duration(diff / rhs); }
|
||||||
explicit time_duration(boost::int64_t d) : diff(d) {}
|
explicit time_duration(boost::int64_t d) : diff(d) {}
|
||||||
time_duration& operator-=(time_duration const& c) { diff -= c.diff; return *this; }
|
time_duration& operator-=(time_duration const& c)
|
||||||
time_duration& operator+=(time_duration const& c) { diff += c.diff; return *this; }
|
{ diff -= c.diff; return *this; }
|
||||||
|
time_duration& operator+=(time_duration const& c)
|
||||||
|
{ diff += c.diff; return *this; }
|
||||||
time_duration& operator*=(int v) { diff *= v; return *this; }
|
time_duration& operator*=(int v) { diff *= v; return *this; }
|
||||||
time_duration operator+(time_duration const& c) { return time_duration(diff + c.diff); }
|
time_duration operator+(time_duration const& c)
|
||||||
time_duration operator-(time_duration const& c) { return time_duration(diff - c.diff); }
|
{ return time_duration(diff + c.diff); }
|
||||||
|
time_duration operator-(time_duration const& c)
|
||||||
|
{ return time_duration(diff - c.diff); }
|
||||||
|
|
||||||
// internal
|
// internal
|
||||||
boost::int64_t diff;
|
boost::int64_t diff;
|
||||||
@ -73,8 +80,11 @@ namespace libtorrent
|
|||||||
// This type represents a point in time.
|
// This type represents a point in time.
|
||||||
struct TORRENT_EXPORT ptime
|
struct TORRENT_EXPORT ptime
|
||||||
{
|
{
|
||||||
|
// hidden
|
||||||
ptime() {}
|
ptime() {}
|
||||||
explicit ptime(boost::uint64_t t): time(t) {}
|
explicit ptime(boost::uint64_t t): time(t) {}
|
||||||
|
|
||||||
|
// these operators have the same semantics as signed 64 bit integers
|
||||||
ptime& operator+=(time_duration rhs) { time += rhs.diff; return *this; }
|
ptime& operator+=(time_duration rhs) { time += rhs.diff; return *this; }
|
||||||
ptime& operator-=(time_duration rhs) { time -= rhs.diff; return *this; }
|
ptime& operator-=(time_duration rhs) { time -= rhs.diff; return *this; }
|
||||||
|
|
||||||
@ -82,8 +92,10 @@ namespace libtorrent
|
|||||||
boost::uint64_t time;
|
boost::uint64_t time;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// returns true of the time duration is less than 0
|
||||||
inline bool is_negative(time_duration dt) { return dt.diff < 0; }
|
inline bool is_negative(time_duration dt) { return dt.diff < 0; }
|
||||||
|
|
||||||
|
// all operators have the same semantics as signed 64 bit integers
|
||||||
inline bool operator>(ptime lhs, ptime rhs)
|
inline bool operator>(ptime lhs, ptime rhs)
|
||||||
{ return lhs.time > rhs.time; }
|
{ return lhs.time > rhs.time; }
|
||||||
inline bool operator>=(ptime lhs, ptime rhs)
|
inline bool operator>=(ptime lhs, ptime rhs)
|
||||||
@ -110,7 +122,6 @@ namespace libtorrent
|
|||||||
{ return time_duration(boost::int64_t(lhs.diff * rhs)); }
|
{ return time_duration(boost::int64_t(lhs.diff * rhs)); }
|
||||||
inline time_duration operator*(int lhs, time_duration rhs)
|
inline time_duration operator*(int lhs, time_duration rhs)
|
||||||
{ return time_duration(boost::int64_t(lhs * rhs.diff)); }
|
{ return time_duration(boost::int64_t(lhs * rhs.diff)); }
|
||||||
|
|
||||||
inline time_duration operator-(ptime lhs, ptime rhs)
|
inline time_duration operator-(ptime lhs, ptime rhs)
|
||||||
{ return time_duration(lhs.time - rhs.time); }
|
{ return time_duration(lhs.time - rhs.time); }
|
||||||
inline ptime operator+(ptime lhs, time_duration rhs)
|
inline ptime operator+(ptime lhs, time_duration rhs)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
Copyright (c) 2007-2012, Arvid Norberg
|
Copyright (c) 2007-2014, Arvid Norberg
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
@ -41,7 +41,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
// OVERVIEW
|
// OVERVIEW
|
||||||
//
|
//
|
||||||
// This section contains fundamental time types used internall by
|
// This section contains fundamental time types used internally by
|
||||||
// libtorrent and exposed through various places in the API. The two
|
// libtorrent and exposed through various places in the API. The two
|
||||||
// basic types are ``ptime`` and ``time_duration``. The first represents
|
// basic types are ``ptime`` and ``time_duration``. The first represents
|
||||||
// a point in time and the second the difference between two points
|
// a point in time and the second the difference between two points
|
||||||
@ -56,28 +56,41 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||||||
// .. note::
|
// .. note::
|
||||||
// In a future version of libtorrent, these types will be replaced
|
// In a future version of libtorrent, these types will be replaced
|
||||||
// by the standard timer types from ``std::chrono``.
|
// by the standard timer types from ``std::chrono``.
|
||||||
|
//
|
||||||
|
|
||||||
namespace libtorrent
|
namespace libtorrent
|
||||||
{
|
{
|
||||||
TORRENT_EXTRA_EXPORT char const* time_now_string();
|
TORRENT_EXTRA_EXPORT char const* time_now_string();
|
||||||
std::string log_time();
|
std::string log_time();
|
||||||
|
|
||||||
|
// returns the current time, as represented by ptime. The
|
||||||
|
// resolution of this timer is about 100 ms.
|
||||||
TORRENT_EXPORT ptime const& time_now();
|
TORRENT_EXPORT ptime const& time_now();
|
||||||
|
|
||||||
|
// returns the current time as represented by ptime. This is
|
||||||
|
// more expensive than time_now(), but provides as high resolution
|
||||||
|
// as the operating system can provide.
|
||||||
TORRENT_EXPORT ptime time_now_hires();
|
TORRENT_EXPORT ptime time_now_hires();
|
||||||
|
|
||||||
|
// the earliest and latest possible time points
|
||||||
|
// representable by ptime.
|
||||||
TORRENT_EXPORT ptime min_time();
|
TORRENT_EXPORT ptime min_time();
|
||||||
TORRENT_EXPORT ptime max_time();
|
TORRENT_EXPORT ptime max_time();
|
||||||
|
|
||||||
#if defined TORRENT_USE_BOOST_DATE_TIME || defined TORRENT_USE_QUERY_PERFORMANCE_TIMER
|
#if defined TORRENT_USE_BOOST_DATE_TIME || defined TORRENT_USE_QUERY_PERFORMANCE_TIMER
|
||||||
|
|
||||||
TORRENT_EXPORT time_duration seconds(int s);
|
// returns a time_duration representing the specified number of seconds, milliseconds
|
||||||
TORRENT_EXPORT time_duration milliseconds(int s);
|
// microseconds, minutes and hours.
|
||||||
TORRENT_EXPORT time_duration microsec(int s);
|
TORRENT_EXPORT time_duration seconds(boost::int64_t s);
|
||||||
TORRENT_EXPORT time_duration minutes(int s);
|
TORRENT_EXPORT time_duration milliseconds(boost::int64_t s);
|
||||||
TORRENT_EXPORT time_duration hours(int s);
|
TORRENT_EXPORT time_duration microsec(boost::int64_t s);
|
||||||
|
TORRENT_EXPORT time_duration minutes(boost::int64_t s);
|
||||||
|
TORRENT_EXPORT time_duration hours(boost::int64_t s);
|
||||||
|
|
||||||
TORRENT_EXPORT int total_seconds(time_duration td);
|
// returns the number of seconds, milliseconds and microseconds
|
||||||
TORRENT_EXPORT int total_milliseconds(time_duration td);
|
// a time_duration represents.
|
||||||
|
TORRENT_EXPORT boost::int64_t total_seconds(time_duration td);
|
||||||
|
TORRENT_EXPORT boost::int64_t total_milliseconds(time_duration td);
|
||||||
TORRENT_EXPORT boost::int64_t total_microseconds(time_duration td);
|
TORRENT_EXPORT boost::int64_t total_microseconds(time_duration td);
|
||||||
|
|
||||||
#elif TORRENT_USE_CLOCK_GETTIME || TORRENT_USE_SYSTEM_TIME || TORRENT_USE_ABSOLUTE_TIME
|
#elif TORRENT_USE_CLOCK_GETTIME || TORRENT_USE_SYSTEM_TIME || TORRENT_USE_ABSOLUTE_TIME
|
||||||
|
@ -2392,7 +2392,7 @@ namespace libtorrent
|
|||||||
for (int processed = 0; processed < 4 * 1024 * 1024; processed += piece_size)
|
for (int processed = 0; processed < 4 * 1024 * 1024; processed += piece_size)
|
||||||
{
|
{
|
||||||
ptime now = time_now_hires();
|
ptime now = time_now_hires();
|
||||||
TORRENT_ASSERT(now >= m_last_file_check);
|
//TORRENT_ASSERT(now >= m_last_file_check);
|
||||||
// this happens sometimes on windows for some reason
|
// this happens sometimes on windows for some reason
|
||||||
if (now < m_last_file_check) now = m_last_file_check;
|
if (now < m_last_file_check) now = m_last_file_check;
|
||||||
|
|
||||||
|
@ -449,7 +449,7 @@ void traversal_algorithm::status(dht_lookup& l)
|
|||||||
observer& o = **i;
|
observer& o = **i;
|
||||||
if (o.flags & observer::flag_queried)
|
if (o.flags & observer::flag_queried)
|
||||||
{
|
{
|
||||||
last_sent = (std::min)(last_sent, total_seconds(now - o.sent()));
|
last_sent = (std::min)(last_sent, int(total_seconds(now - o.sent())));
|
||||||
if (o.has_short_timeout()) ++l.first_timeout;
|
if (o.has_short_timeout()) ++l.first_timeout;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
Copyright (c) 2009-2012, Arvid Norberg
|
Copyright (c) 2009-2014, Arvid Norberg
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
@ -58,12 +58,6 @@ namespace libtorrent
|
|||||||
|
|
||||||
char const* time_now_string()
|
char const* time_now_string()
|
||||||
{
|
{
|
||||||
// time_t t = std::time(0);
|
|
||||||
// tm* timeinfo = std::localtime(&t);
|
|
||||||
// static char str[200];
|
|
||||||
// std::strftime(str, 200, "%b %d %X", timeinfo);
|
|
||||||
// return str;
|
|
||||||
|
|
||||||
static const ptime start = time_now_hires();
|
static const ptime start = time_now_hires();
|
||||||
static char ret[200];
|
static char ret[200];
|
||||||
int t = total_milliseconds(time_now_hires() - start);
|
int t = total_milliseconds(time_now_hires() - start);
|
||||||
@ -82,7 +76,7 @@ namespace libtorrent
|
|||||||
{
|
{
|
||||||
static const ptime start = time_now_hires();
|
static const ptime start = time_now_hires();
|
||||||
char ret[200];
|
char ret[200];
|
||||||
snprintf(ret, sizeof(ret), "%"PRId64, total_microseconds(time_now_hires() - start));
|
snprintf(ret, sizeof(ret), "%" PRId64, total_microseconds(time_now_hires() - start));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -99,15 +93,15 @@ namespace libtorrent
|
|||||||
{ return boost::posix_time::ptime(boost::posix_time::min_date_time); }
|
{ return boost::posix_time::ptime(boost::posix_time::min_date_time); }
|
||||||
ptime max_time()
|
ptime max_time()
|
||||||
{ return boost::posix_time::ptime(boost::posix_time::max_date_time); }
|
{ return boost::posix_time::ptime(boost::posix_time::max_date_time); }
|
||||||
time_duration seconds(int s) { return boost::posix_time::seconds(s); }
|
time_duration seconds(boost::int64_t s) { return boost::posix_time::seconds(s); }
|
||||||
time_duration milliseconds(int s) { return boost::posix_time::milliseconds(s); }
|
time_duration milliseconds(boost::int64_t s) { return boost::posix_time::milliseconds(s); }
|
||||||
time_duration microsec(int s) { return boost::posix_time::microsec(s); }
|
time_duration microsec(boost::int64_t s) { return boost::posix_time::microsec(s); }
|
||||||
time_duration minutes(int s) { return boost::posix_time::minutes(s); }
|
time_duration minutes(boost::int64_t s) { return boost::posix_time::minutes(s); }
|
||||||
time_duration hours(int s) { return boost::posix_time::hours(s); }
|
time_duration hours(boost::int64_t s) { return boost::posix_time::hours(s); }
|
||||||
|
|
||||||
int total_seconds(time_duration td)
|
boost::int64_t total_seconds(time_duration td)
|
||||||
{ return td.total_seconds(); }
|
{ return td.total_seconds(); }
|
||||||
int total_milliseconds(time_duration td)
|
boost::int64_t total_milliseconds(time_duration td)
|
||||||
{ return td.total_milliseconds(); }
|
{ return td.total_milliseconds(); }
|
||||||
boost::int64_t total_microseconds(time_duration td)
|
boost::int64_t total_microseconds(time_duration td)
|
||||||
{ return td.total_microseconds(); }
|
{ return td.total_microseconds(); }
|
||||||
@ -188,14 +182,14 @@ namespace libtorrent
|
|||||||
return ptime(now.QuadPart);
|
return ptime(now.QuadPart);
|
||||||
}
|
}
|
||||||
|
|
||||||
int total_seconds(time_duration td)
|
boost::int64_t total_seconds(time_duration td)
|
||||||
{
|
{
|
||||||
return int(performance_counter_to_microseconds(td.diff)
|
return boost::int64_t(performance_counter_to_microseconds(td.diff)
|
||||||
/ 1000000);
|
/ 1000000);
|
||||||
}
|
}
|
||||||
int total_milliseconds(time_duration td)
|
boost::int64_t total_milliseconds(time_duration td)
|
||||||
{
|
{
|
||||||
return int(performance_counter_to_microseconds(td.diff)
|
return boost::uint64_t(performance_counter_to_microseconds(td.diff)
|
||||||
/ 1000);
|
/ 1000);
|
||||||
}
|
}
|
||||||
boost::int64_t total_microseconds(time_duration td)
|
boost::int64_t total_microseconds(time_duration td)
|
||||||
@ -203,26 +197,26 @@ namespace libtorrent
|
|||||||
return performance_counter_to_microseconds(td.diff);
|
return performance_counter_to_microseconds(td.diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
time_duration microsec(int s)
|
time_duration microsec(boost::int64_t s)
|
||||||
{
|
{
|
||||||
return time_duration(microseconds_to_performance_counter(s));
|
return time_duration(microseconds_to_performance_counter(s));
|
||||||
}
|
}
|
||||||
time_duration milliseconds(int s)
|
time_duration milliseconds(boost::int64_t s)
|
||||||
{
|
{
|
||||||
return time_duration(microseconds_to_performance_counter(
|
return time_duration(microseconds_to_performance_counter(
|
||||||
s * 1000));
|
s * 1000));
|
||||||
}
|
}
|
||||||
time_duration seconds(int s)
|
time_duration seconds(boost::int64_t s)
|
||||||
{
|
{
|
||||||
return time_duration(microseconds_to_performance_counter(
|
return time_duration(microseconds_to_performance_counter(
|
||||||
s * 1000000));
|
s * 1000000));
|
||||||
}
|
}
|
||||||
time_duration minutes(int s)
|
time_duration minutes(boost::int64_t s)
|
||||||
{
|
{
|
||||||
return time_duration(microseconds_to_performance_counter(
|
return time_duration(microseconds_to_performance_counter(
|
||||||
s * 1000000 * 60));
|
s * 1000000 * 60));
|
||||||
}
|
}
|
||||||
time_duration hours(int s)
|
time_duration hours(boost::int64_t s)
|
||||||
{
|
{
|
||||||
return time_duration(microseconds_to_performance_counter(
|
return time_duration(microseconds_to_performance_counter(
|
||||||
s * 1000000 * 60 * 60));
|
s * 1000000 * 60 * 60));
|
||||||
|
@ -133,8 +133,8 @@ namespace libtorrent
|
|||||||
if (m_completion_timeout > 0)
|
if (m_completion_timeout > 0)
|
||||||
{
|
{
|
||||||
timeout = timeout == 0
|
timeout = timeout == 0
|
||||||
? m_completion_timeout - total_seconds(m_read_time - m_start_time)
|
? int(m_completion_timeout - total_seconds(m_read_time - m_start_time))
|
||||||
: (std::min)(m_completion_timeout - total_seconds(m_read_time - m_start_time), timeout);
|
: (std::min)(int(m_completion_timeout - total_seconds(m_read_time - m_start_time)), timeout);
|
||||||
}
|
}
|
||||||
#if defined TORRENT_ASIO_DEBUGGING
|
#if defined TORRENT_ASIO_DEBUGGING
|
||||||
add_outstanding_async("timeout_handler::timeout_callback");
|
add_outstanding_async("timeout_handler::timeout_callback");
|
||||||
|
Loading…
Reference in New Issue
Block a user