PageRenderTime 12ms CodeModel.GetById 2ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

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