]>
Commit | Line | Data |
---|---|---|
1 | // boost thread_clock.cpp -----------------------------------------------------------// | |
2 | ||
3 | // Copyright 2010 Vicente J. Botet Escriba | |
4 | ||
5 | // Distributed under the Boost Software License, Version 1.0. | |
6 | // See http://www.boost.org/LICENSE_1_0.txt | |
7 | ||
8 | // See http://www.boost.org/libs/chrono for documentation. | |
9 | ||
10 | //--------------------------------------------------------------------------------------// | |
11 | #ifndef BOOST_CHRONO_DETAIL_INLINED_WIN_THREAD_CLOCK_HPP | |
12 | #define BOOST_CHRONO_DETAIL_INLINED_WIN_THREAD_CLOCK_HPP | |
13 | ||
14 | #include <boost/chrono/config.hpp> | |
15 | #include <boost/chrono/thread_clock.hpp> | |
16 | #include <cassert> | |
17 | #include <boost/assert.hpp> | |
18 | ||
19 | #include <boost/detail/winapi/get_last_error.hpp> | |
20 | #include <boost/detail/winapi/get_current_thread.hpp> | |
21 | #include <boost/detail/winapi/get_thread_times.hpp> | |
22 | ||
23 | namespace boost | |
24 | { | |
25 | namespace chrono | |
26 | { | |
27 | ||
28 | #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING | |
29 | thread_clock::time_point thread_clock::now( system::error_code & ec ) | |
30 | { | |
31 | // note that Windows uses 100 nanosecond ticks for FILETIME | |
32 | boost::detail::winapi::FILETIME_ creation, exit, user_time, system_time; | |
33 | ||
34 | if ( boost::detail::winapi::GetThreadTimes( | |
35 | boost::detail::winapi::GetCurrentThread (), &creation, &exit, | |
36 | &system_time, &user_time ) ) | |
37 | { | |
38 | duration user = duration( | |
39 | ((static_cast<duration::rep>(user_time.dwHighDateTime) << 32) | |
40 | | user_time.dwLowDateTime) * 100 ); | |
41 | ||
42 | duration system = duration( | |
43 | ((static_cast<duration::rep>(system_time.dwHighDateTime) << 32) | |
44 | | system_time.dwLowDateTime) * 100 ); | |
45 | ||
46 | if (!BOOST_CHRONO_IS_THROWS(ec)) | |
47 | { | |
48 | ec.clear(); | |
49 | } | |
50 | return time_point(system+user); | |
51 | ||
52 | } | |
53 | else | |
54 | { | |
55 | if (BOOST_CHRONO_IS_THROWS(ec)) | |
56 | { | |
57 | boost::throw_exception( | |
58 | system::system_error( | |
59 | boost::detail::winapi::GetLastError(), | |
60 | BOOST_CHRONO_SYSTEM_CATEGORY, | |
61 | "chrono::thread_clock" )); | |
62 | } | |
63 | else | |
64 | { | |
65 | ec.assign( boost::detail::winapi::GetLastError(), BOOST_CHRONO_SYSTEM_CATEGORY ); | |
66 | return thread_clock::time_point(duration(0)); | |
67 | } | |
68 | } | |
69 | } | |
70 | #endif | |
71 | ||
72 | thread_clock::time_point thread_clock::now() BOOST_NOEXCEPT | |
73 | { | |
74 | ||
75 | // note that Windows uses 100 nanosecond ticks for FILETIME | |
76 | boost::detail::winapi::FILETIME_ creation, exit, user_time, system_time; | |
77 | ||
78 | if ( boost::detail::winapi::GetThreadTimes( | |
79 | boost::detail::winapi::GetCurrentThread (), &creation, &exit, | |
80 | &system_time, &user_time ) ) | |
81 | { | |
82 | duration user = duration( | |
83 | ((static_cast<duration::rep>(user_time.dwHighDateTime) << 32) | |
84 | | user_time.dwLowDateTime) * 100 ); | |
85 | ||
86 | duration system = duration( | |
87 | ((static_cast<duration::rep>(system_time.dwHighDateTime) << 32) | |
88 | | system_time.dwLowDateTime) * 100 ); | |
89 | ||
90 | return time_point(system+user); | |
91 | } | |
92 | else | |
93 | { | |
94 | BOOST_ASSERT(0 && "Boost::Chrono - Internal Error"); | |
95 | return time_point(); | |
96 | } | |
97 | ||
98 | } | |
99 | ||
100 | } // namespace chrono | |
101 | } // namespace boost | |
102 | ||
103 | #endif |