/Src/Dependencies/Boost/boost/chrono/detail/inlined/win/process_clock.hpp

http://hadesmem.googlecode.com/ · C++ Header · 80 lines · 58 code · 13 blank · 9 comment · 5 complexity · 078f7a57136a0e8b9b895c955107b910 MD5 · raw file

  1. // boost process_timer.cpp -----------------------------------------------------------//
  2. // Copyright Beman Dawes 1994, 2006, 2008
  3. // Copyright 2009-2010 Vicente J. Botet Escriba
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // See http://www.boost.org/LICENSE_1_0.txt
  6. // See http://www.boost.org/libs/chrono for documentation.
  7. //--------------------------------------------------------------------------------------//
  8. #ifndef BOOST_CHRONO_DETAIL_INLINED_WIN_PROCESS_CLOCK_HPP
  9. #define BOOST_CHRONO_DETAIL_INLINED_WIN_PROCESS_CLOCK_HPP
  10. #include <boost/chrono/config.hpp>
  11. #include <boost/chrono/system_clocks.hpp>
  12. #include <boost/chrono/process_times.hpp>
  13. #include <cassert>
  14. #include <boost/detail/win/GetLastError.hpp>
  15. #include <boost/detail/win/GetCurrentProcess.hpp>
  16. #include <boost/detail/win/GetProcessTimes.hpp>
  17. namespace boost
  18. {
  19. namespace chrono
  20. {
  21. void process_clock::now( process_times & times_, system::error_code & ec )
  22. {
  23. // note that Windows uses 100 nanosecond ticks for FILETIME
  24. boost::detail::win32::FILETIME_ creation, exit, user_time, system_time;
  25. times_.real = duration( steady_clock::now().time_since_epoch().count() );
  26. #ifdef UNDER_CE
  27. // Windows CE does not support GetProcessTimes
  28. assert( 0 && "GetProcessTimes not supported under Windows CE" );
  29. times_.real = times_.system = times_.user = nanoseconds(-1);
  30. #else
  31. if ( boost::detail::win32::GetProcessTimes(
  32. boost::detail::win32::GetCurrentProcess(), &creation, &exit,
  33. &system_time, &user_time ) )
  34. {
  35. if (!BOOST_CHRONO_IS_THROWS(ec))
  36. {
  37. ec.clear();
  38. }
  39. times_.user = duration(
  40. ((static_cast<time_point::rep>(user_time.dwHighDateTime) << 32)
  41. | user_time.dwLowDateTime) * 100 );
  42. times_.system = duration(
  43. ((static_cast<time_point::rep>(system_time.dwHighDateTime) << 32)
  44. | system_time.dwLowDateTime) * 100 );
  45. }
  46. else
  47. {
  48. boost::detail::win32::DWORD_ cause = boost::detail::win32::GetLastError();
  49. if (BOOST_CHRONO_IS_THROWS(ec))
  50. {
  51. boost::throw_exception(
  52. system::system_error(
  53. cause,
  54. BOOST_CHRONO_SYSTEM_CATEGORY,
  55. "chrono::process_clock" ));
  56. }
  57. else
  58. {
  59. ec.assign( cause, BOOST_CHRONO_SYSTEM_CATEGORY );
  60. times_.real = times_.system = times_.user = nanoseconds(-1);
  61. }
  62. }
  63. #endif
  64. }
  65. } // namespace chrono
  66. } // namespace boost
  67. #endif