]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/chrono/detail/inlined/win/thread_clock.hpp
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / boost / boost / chrono / detail / inlined / win / thread_clock.hpp
CommitLineData
7c673cae
FG
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
f67539c2
TL
19#include <boost/winapi/get_last_error.hpp>
20#include <boost/winapi/get_current_thread.hpp>
21#include <boost/winapi/get_thread_times.hpp>
7c673cae
FG
22
23namespace boost
24{
25namespace chrono
26{
27
28#if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
29thread_clock::time_point thread_clock::now( system::error_code & ec )
30{
31 // note that Windows uses 100 nanosecond ticks for FILETIME
f67539c2 32 boost::winapi::FILETIME_ creation, exit, user_time, system_time;
7c673cae 33
f67539c2
TL
34 if ( boost::winapi::GetThreadTimes(
35 boost::winapi::GetCurrentThread (), &creation, &exit,
7c673cae
FG
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
92f5a8d4 46 if (!::boost::chrono::is_throws(ec))
7c673cae
FG
47 {
48 ec.clear();
49 }
50 return time_point(system+user);
51
52 }
53 else
54 {
92f5a8d4 55 if (::boost::chrono::is_throws(ec))
7c673cae
FG
56 {
57 boost::throw_exception(
58 system::system_error(
f67539c2 59 boost::winapi::GetLastError(),
92f5a8d4 60 ::boost::system::system_category(),
7c673cae
FG
61 "chrono::thread_clock" ));
62 }
63 else
64 {
f67539c2 65 ec.assign( boost::winapi::GetLastError(), ::boost::system::system_category() );
7c673cae
FG
66 return thread_clock::time_point(duration(0));
67 }
68 }
69}
70#endif
71
72thread_clock::time_point thread_clock::now() BOOST_NOEXCEPT
73{
74
75 // note that Windows uses 100 nanosecond ticks for FILETIME
f67539c2 76 boost::winapi::FILETIME_ creation, exit, user_time, system_time;
7c673cae 77
f67539c2
TL
78 if ( boost::winapi::GetThreadTimes(
79 boost::winapi::GetCurrentThread (), &creation, &exit,
7c673cae
FG
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