N3191: C++ Timeout Specification

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@119909 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Howard Hinnant 2010-11-20 19:16:30 +00:00
parent f048fe3a09
commit f8f852138f
23 changed files with 63 additions and 63 deletions

View File

@ -382,11 +382,11 @@ condition_variable::wait_for(unique_lock<mutex>& __lk,
const chrono::duration<_Rep, _Period>& __d)
{
using namespace chrono;
system_clock::time_point __s_now = system_clock::now();
monotonic_clock::time_point __c_now = monotonic_clock::now();
system_clock::time_point __s_now = system_clock::now();
steady_clock::time_point __c_now = steady_clock::now();
__do_timed_wait(__lk, __s_now + __ceil<nanoseconds>(__d));
return monotonic_clock::now() - __c_now < __d ? cv_status::no_timeout :
cv_status::timeout;
return steady_clock::now() - __c_now < __d ? cv_status::no_timeout :
cv_status::timeout;
}
template <class _Rep, class _Period, class _Predicate>
@ -396,7 +396,7 @@ condition_variable::wait_for(unique_lock<mutex>& __lk,
const chrono::duration<_Rep, _Period>& __d,
_Predicate __pred)
{
return wait_until(__lk, chrono::monotonic_clock::now() + __d,
return wait_until(__lk, chrono::steady_clock::now() + __d,
_STD::move(__pred));
}

View File

@ -223,26 +223,26 @@ public:
typedef duration::rep rep;
typedef duration::period period;
typedef chrono::time_point<system_clock> time_point;
static const bool is_monotonic = false;
static const bool is_steady = false;
static time_point now();
static time_t to_time_t (const time_point& __t);
static time_point from_time_t(time_t __t);
};
class monotonic_clock
class steady_clock
{
public:
typedef nanoseconds duration;
typedef duration::rep rep;
typedef duration::period period;
typedef chrono::time_point<monotonic_clock, duration> time_point;
static const bool is_monotonic = true;
typedef chrono::time_point<steady_clock, duration> time_point;
static const bool is_steady = true;
static time_point now();
};
typedef monotonic_clock high_resolution_clock;
typedef steady_clock high_resolution_clock;
} // chrono
@ -843,26 +843,26 @@ public:
typedef duration::rep rep;
typedef duration::period period;
typedef chrono::time_point<system_clock> time_point;
static const bool is_monotonic = false;
static const bool is_steady = false;
static time_point now();
static time_t to_time_t (const time_point& __t);
static time_point from_time_t(time_t __t);
};
class _LIBCPP_VISIBLE monotonic_clock
class _LIBCPP_VISIBLE steady_clock
{
public:
typedef nanoseconds duration;
typedef duration::rep rep;
typedef duration::period period;
typedef chrono::time_point<monotonic_clock, duration> time_point;
static const bool is_monotonic = true;
typedef chrono::time_point<steady_clock, duration> time_point;
static const bool is_steady = true;
static time_point now();
};
typedef monotonic_clock high_resolution_clock;
typedef steady_clock high_resolution_clock;
} // chrono

View File

@ -232,7 +232,7 @@ cv_status
condition_variable_any::wait_for(_Lock& __lock,
const chrono::duration<_Rep, _Period>& __d)
{
return wait_until(__lock, chrono::monotonic_clock::now() + __d);
return wait_until(__lock, chrono::steady_clock::now() + __d);
}
template <class _Lock, class _Rep, class _Period, class _Predicate>
@ -242,7 +242,7 @@ condition_variable_any::wait_for(_Lock& __lock,
const chrono::duration<_Rep, _Period>& __d,
_Predicate __pred)
{
return wait_until(__lock, chrono::monotonic_clock::now() + __d,
return wait_until(__lock, chrono::steady_clock::now() + __d,
_STD::move(__pred));
}

View File

@ -603,7 +603,7 @@ inline _LIBCPP_INLINE_VISIBILITY
future_status
__assoc_sub_state::wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
{
return wait_until(chrono::monotonic_clock::now() + __rel_time);
return wait_until(chrono::steady_clock::now() + __rel_time);
}
template <class _R>

View File

@ -221,7 +221,7 @@ public:
template <class _Rep, class _Period>
_LIBCPP_INLINE_VISIBILITY
bool try_lock_for(const chrono::duration<_Rep, _Period>& __d)
{return try_lock_until(chrono::monotonic_clock::now() + __d);}
{return try_lock_until(chrono::steady_clock::now() + __d);}
template <class _Clock, class _Duration>
bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __t);
void unlock();
@ -264,7 +264,7 @@ public:
template <class _Rep, class _Period>
_LIBCPP_INLINE_VISIBILITY
bool try_lock_for(const chrono::duration<_Rep, _Period>& __d)
{return try_lock_until(chrono::monotonic_clock::now() + __d);}
{return try_lock_until(chrono::steady_clock::now() + __d);}
template <class _Clock, class _Duration>
bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __t);
void unlock();

View File

@ -406,10 +406,10 @@ sleep_until(const chrono::time_point<_Clock, _Duration>& __t)
template <class _Duration>
inline _LIBCPP_INLINE_VISIBILITY
void
sleep_until(const chrono::time_point<chrono::monotonic_clock, _Duration>& __t)
sleep_until(const chrono::time_point<chrono::steady_clock, _Duration>& __t)
{
using namespace chrono;
sleep_for(__t - monotonic_clock::now());
sleep_for(__t - steady_clock::now());
}
inline _LIBCPP_INLINE_VISIBILITY

View File

@ -44,7 +44,7 @@ system_clock::from_time_t(time_t t)
return system_clock::time_point(seconds(t));
}
// monotonic_clock
// steady_clock
#if __APPLE__
// mach_absolute_time() * MachInfo.numer / MachInfo.denom is the number of
@ -58,15 +58,15 @@ system_clock::from_time_t(time_t t)
#pragma GCC visibility push(hidden)
static
monotonic_clock::rep
monotonic_simplified()
steady_clock::rep
steady_simplified()
{
return mach_absolute_time();
}
static
double
compute_monotonic_factor()
compute_steady_factor()
{
mach_timebase_info_data_t MachInfo;
mach_timebase_info(&MachInfo);
@ -74,32 +74,32 @@ compute_monotonic_factor()
}
static
monotonic_clock::rep
monotonic_full()
steady_clock::rep
steady_full()
{
static const double factor = compute_monotonic_factor();
return static_cast<monotonic_clock::rep>(mach_absolute_time() * factor);
static const double factor = compute_steady_factor();
return static_cast<steady_clock::rep>(mach_absolute_time() * factor);
}
typedef monotonic_clock::rep (*FP)();
typedef steady_clock::rep (*FP)();
static
FP
init_monotonic_clock()
init_steady_clock()
{
mach_timebase_info_data_t MachInfo;
mach_timebase_info(&MachInfo);
if (MachInfo.numer == MachInfo.denom)
return &monotonic_simplified;
return &monotonic_full;
return &steady_simplified;
return &steady_full;
}
#pragma GCC visibility pop
monotonic_clock::time_point
monotonic_clock::now()
steady_clock::time_point
steady_clock::now()
{
static FP fp = init_monotonic_clock();
static FP fp = init_steady_clock();
return time_point(duration(fp()));
}
@ -109,12 +109,12 @@ monotonic_clock::now()
// _POSIX_MONOTONIC_CLOCK and fall back to something else if those
// don't exist.
// Warning: If this is not truly monotonic, then it is non-conforming. It is
// Warning: If this is not truly steady, then it is non-conforming. It is
// better for it to not exist and have the rest of libc++ use system_clock
// instead.
monotonic_clock::time_point
monotonic_clock::now()
steady_clock::time_point
steady_clock::now()
{
struct timespec tp;
if (0 != clock_gettime(CLOCK_MONOTONIC, &tp))

View File

@ -28,13 +28,13 @@ struct Clock
typedef duration::rep rep;
typedef duration::period period;
typedef std::chrono::time_point<Clock> time_point;
static const bool is_monotonic = true;
static const bool is_steady = true;
static time_point now()
{
using namespace std::chrono;
return time_point(duration_cast<duration>(
monotonic_clock::now().time_since_epoch()
steady_clock::now().time_since_epoch()
));
}
};

View File

@ -29,13 +29,13 @@ struct Clock
typedef duration::rep rep;
typedef duration::period period;
typedef std::chrono::time_point<Clock> time_point;
static const bool is_monotonic = true;
static const bool is_steady = true;
static time_point now()
{
using namespace std::chrono;
return time_point(duration_cast<duration>(
monotonic_clock::now().time_since_epoch()
steady_clock::now().time_since_epoch()
));
}
};

View File

@ -27,13 +27,13 @@ struct Clock
typedef duration::rep rep;
typedef duration::period period;
typedef std::chrono::time_point<Clock> time_point;
static const bool is_monotonic = true;
static const bool is_steady = true;
static time_point now()
{
using namespace std::chrono;
return time_point(duration_cast<duration>(
monotonic_clock::now().time_since_epoch()
steady_clock::now().time_since_epoch()
));
}
};

View File

@ -29,13 +29,13 @@ struct Clock
typedef duration::rep rep;
typedef duration::period period;
typedef std::chrono::time_point<Clock> time_point;
static const bool is_monotonic = true;
static const bool is_steady = true;
static time_point now()
{
using namespace std::chrono;
return time_point(duration_cast<duration>(
monotonic_clock::now().time_since_epoch()
steady_clock::now().time_since_epoch()
));
}
};

View File

@ -21,7 +21,7 @@
std::timed_mutex m;
typedef std::chrono::monotonic_clock Clock;
typedef std::chrono::steady_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;

View File

@ -21,7 +21,7 @@
std::timed_mutex m;
typedef std::chrono::monotonic_clock Clock;
typedef std::chrono::steady_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;

View File

@ -36,7 +36,7 @@ mutex m;
int main()
{
typedef std::chrono::monotonic_clock Clock;
typedef std::chrono::steady_clock Clock;
std::unique_lock<mutex> lk(m, std::defer_lock);
assert(lk.try_lock_until(Clock::now()) == true);
assert(try_lock_until_called == true);

View File

@ -21,7 +21,7 @@
std::timed_mutex m;
typedef std::chrono::monotonic_clock Clock;
typedef std::chrono::steady_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;

View File

@ -21,7 +21,7 @@
std::timed_mutex m;
typedef std::chrono::monotonic_clock Clock;
typedef std::chrono::steady_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;

View File

@ -21,7 +21,7 @@
std::recursive_timed_mutex m;
typedef std::chrono::monotonic_clock Clock;
typedef std::chrono::steady_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;

View File

@ -21,7 +21,7 @@
std::recursive_timed_mutex m;
typedef std::chrono::monotonic_clock Clock;
typedef std::chrono::steady_clock Clock;
typedef Clock::time_point time_point;
typedef Clock::duration duration;
typedef std::chrono::milliseconds ms;

View File

@ -9,7 +9,7 @@ class Clock
typedef duration::rep rep;
typedef duration::period period;
typedef std::chrono::time_point<Clock, duration> time_point;
static const bool is_monotonic = false;
static const bool is_steady = false;
static time_point now();
};

View File

@ -21,5 +21,5 @@ int main()
static_assert((std::is_same<C::rep, C::duration::rep>::value), "");
static_assert((std::is_same<C::period, C::duration::period>::value), "");
static_assert((std::is_same<C::duration, C::time_point::duration>::value), "");
static_assert(C::is_monotonic || !C::is_monotonic, "");
static_assert(C::is_steady || !C::is_steady, "");
}

View File

@ -9,7 +9,7 @@
// <chrono>
// monotonic_clock
// steady_clock
// check clock invariants
@ -17,9 +17,9 @@
int main()
{
typedef std::chrono::monotonic_clock C;
typedef std::chrono::steady_clock C;
static_assert((std::is_same<C::rep, C::duration::rep>::value), "");
static_assert((std::is_same<C::period, C::duration::period>::value), "");
static_assert((std::is_same<C::duration, C::time_point::duration>::value), "");
static_assert(C::is_monotonic, "");
static_assert(C::is_steady, "");
}

View File

@ -9,7 +9,7 @@
// <chrono>
// monotonic_clock
// steady_clock
// static time_point now();
@ -18,7 +18,7 @@
int main()
{
typedef std::chrono::monotonic_clock C;
typedef std::chrono::steady_clock C;
C::time_point t1 = C::now();
C::time_point t2 = C::now();
assert(t2 >= t1);

View File

@ -22,5 +22,5 @@ int main()
static_assert((std::is_same<C::period, C::duration::period>::value), "");
static_assert((std::is_same<C::duration, C::time_point::duration>::value), "");
static_assert((std::is_same<C::time_point::clock, C>::value), "");
static_assert((C::is_monotonic || !C::is_monotonic), "");
static_assert((C::is_steady || !C::is_steady), "");
}