mirror of
https://github.com/boostorg/thread.git
synced 2026-02-09 23:42:18 +00:00
Updated format (removed tabs) and added missing copyrights
[SVN r17214]
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2001
|
||||
// Copyright (C) 2001-2003
|
||||
// William E. Kempf
|
||||
//
|
||||
// Permission to use, copy, modify, distribute and sell this software
|
||||
@@ -33,29 +33,30 @@ struct startup_time_info
|
||||
{
|
||||
startup_time_info()
|
||||
{
|
||||
// 1970 Jan 1 at 00:00:00
|
||||
// 1970 Jan 1 at 00:00:00
|
||||
static const DateTimeRec k_sUNIXBase = {1970, 1, 1, 0, 0, 0, 0};
|
||||
static unsigned long s_ulUNIXBaseSeconds = 0UL;
|
||||
|
||||
if(s_ulUNIXBaseSeconds == 0UL)
|
||||
{
|
||||
// calculate the number of seconds between the Mac OS base and the UNIX base
|
||||
// the first time we enter this constructor.
|
||||
// calculate the number of seconds between the Mac OS base and the
|
||||
// UNIX base the first time we enter this constructor.
|
||||
DateToSeconds(&k_sUNIXBase, &s_ulUNIXBaseSeconds);
|
||||
}
|
||||
|
||||
unsigned long ulSeconds;
|
||||
|
||||
// get the time in UpTime units twice, with the time in seconds in the middle.
|
||||
// get the time in UpTime units twice, with the time in seconds in the
|
||||
// middle.
|
||||
uint64_t ullFirstUpTime = force_cast<uint64_t>(UpTime());
|
||||
GetDateTime(&ulSeconds);
|
||||
uint64_t ullSecondUpTime = force_cast<uint64_t>(UpTime());
|
||||
|
||||
// calculate the midpoint of the two UpTimes, and save that.
|
||||
// calculate the midpoint of the two UpTimes, and save that.
|
||||
uint64_t ullAverageUpTime = (ullFirstUpTime + ullSecondUpTime) / 2ULL;
|
||||
m_sStartupAbsoluteTime = force_cast<AbsoluteTime>(ullAverageUpTime);
|
||||
|
||||
// save the number of seconds, recentered at the UNIX base.
|
||||
// save the number of seconds, recentered at the UNIX base.
|
||||
m_ulStartupSeconds = ulSeconds - s_ulUNIXBaseSeconds;
|
||||
}
|
||||
|
||||
@@ -77,10 +78,13 @@ int xtime_get(struct xtime* xtp, int clock_type)
|
||||
#if defined(BOOST_HAS_FTIME)
|
||||
FILETIME ft;
|
||||
GetSystemTimeAsFileTime(&ft);
|
||||
const boost::uint64_t TIMESPEC_TO_FILETIME_OFFSET = ((boost::uint64_t)27111902UL << 32) + (boost::uint64_t)3577643008UL;
|
||||
xtp->sec = (int)((*(__int64*)&ft - TIMESPEC_TO_FILETIME_OFFSET) / 10000000);
|
||||
const boost::uint64_t TIMESPEC_TO_FILETIME_OFFSET =
|
||||
((boost::uint64_t)27111902UL << 32) +
|
||||
(boost::uint64_t)3577643008UL;
|
||||
xtp->sec = (int)((*(__int64*)&ft - TIMESPEC_TO_FILETIME_OFFSET) /
|
||||
10000000);
|
||||
xtp->nsec = (int)((*(__int64*)&ft - TIMESPEC_TO_FILETIME_OFFSET -
|
||||
((__int64)xtp->sec * (__int64)10000000)) * 100);
|
||||
((__int64)xtp->sec * (__int64)10000000)) * 100);
|
||||
return clock_type;
|
||||
#elif defined(BOOST_HAS_GETTIMEOFDAY)
|
||||
struct timeval tv;
|
||||
@@ -96,12 +100,16 @@ int xtime_get(struct xtime* xtp, int clock_type)
|
||||
return clock_type;
|
||||
#elif defined(BOOST_HAS_MPTASKS)
|
||||
using detail::thread::force_cast;
|
||||
// the Mac OS does not have an MP-safe way of getting the date/time, so we use a
|
||||
// delta from the startup time. We _could_ defer this and use something that is
|
||||
// interrupt-safe, but this would be _SLOW_, and we need speed here.
|
||||
// the Mac OS does not have an MP-safe way of getting the date/time,
|
||||
// so we use a delta from the startup time. We _could_ defer this
|
||||
// and use something that is interrupt-safe, but this would be _SLOW_,
|
||||
// and we need speed here.
|
||||
const uint64_t k_ullNanosecondsPerSecond(1000ULL * 1000ULL * 1000ULL);
|
||||
AbsoluteTime sUpTime(UpTime());
|
||||
uint64_t ullNanoseconds(force_cast<uint64_t>(AbsoluteDeltaToNanoseconds(sUpTime, detail::g_sStartupTimeInfo.m_sStartupAbsoluteTime)));
|
||||
uint64_t ullNanoseconds(
|
||||
force_cast<uint64_t>(
|
||||
AbsoluteDeltaToNanoseconds(sUpTime,
|
||||
detail::g_sStartupTimeInfo.m_sStartupAbsoluteTime)));
|
||||
uint64_t ullSeconds = (ullNanoseconds / k_ullNanosecondsPerSecond);
|
||||
ullNanoseconds -= (ullSeconds * k_ullNanosecondsPerSecond);
|
||||
xtp->sec = detail::g_sStartupTimeInfo.m_ulStartupSeconds + ullSeconds;
|
||||
|
||||
Reference in New Issue
Block a user