thread_time.hpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef BOOST_THREAD_TIME_HPP
  2. #define BOOST_THREAD_TIME_HPP
  3. // (C) Copyright 2007 Anthony Williams
  4. //
  5. // Distributed under the Boost Software License, Version 1.0. (See
  6. // accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. #include <boost/date_time/time_clock.hpp>
  9. #include <boost/date_time/microsec_time_clock.hpp>
  10. #include <boost/date_time/posix_time/posix_time_types.hpp>
  11. #include <boost/config/abi_prefix.hpp>
  12. namespace boost
  13. {
  14. typedef boost::posix_time::ptime system_time;
  15. inline system_time get_system_time()
  16. {
  17. #if defined(BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK)
  18. return boost::date_time::microsec_clock<system_time>::universal_time();
  19. #else // defined(BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK)
  20. return boost::date_time::second_clock<system_time>::universal_time();
  21. #endif // defined(BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK)
  22. }
  23. namespace detail
  24. {
  25. inline system_time get_system_time_sentinel()
  26. {
  27. return system_time(boost::posix_time::pos_infin);
  28. }
  29. inline unsigned long get_milliseconds_until(system_time const& target_time)
  30. {
  31. if(target_time.is_pos_infinity())
  32. {
  33. return ~(unsigned long)0;
  34. }
  35. system_time const now=get_system_time();
  36. if(target_time<=now)
  37. {
  38. return 0;
  39. }
  40. return static_cast<unsigned long>((target_time-now).total_milliseconds()+1);
  41. }
  42. }
  43. }
  44. #include <boost/config/abi_suffix.hpp>
  45. #endif