]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/llvm/tools/lldb/include/lldb/Host/TimeValue.h
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / llvm / tools / lldb / include / lldb / Host / TimeValue.h
1 //===-- TimeValue.h ---------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef liblldb_TimeValue_h_
11 #define liblldb_TimeValue_h_
12
13 // C Includes
14 #include <stdint.h>
15 #ifndef _MSC_VER
16 #include <sys/time.h>
17
18 // BEGIN: MinGW work around
19 #if !defined(_STRUCT_TIMESPEC) && !defined(HAVE_STRUCT_TIMESPEC)
20 #include <pthread.h>
21 #endif
22 // END: MinGW work around
23 #endif
24
25 // C++ Includes
26 // Other libraries and framework includes
27 // Project includes
28 #include "lldb/lldb-private.h"
29
30 namespace lldb_private {
31
32 class TimeValue
33 {
34 public:
35     static const uint64_t MicroSecPerSec = 1000000UL;
36     static const uint64_t NanoSecPerSec = 1000000000UL;
37     static const uint64_t NanoSecPerMicroSec = 1000U;
38
39     //------------------------------------------------------------------
40     // Constructors and Destructors
41     //------------------------------------------------------------------
42     TimeValue();
43     TimeValue(const TimeValue& rhs);
44     TimeValue(const struct timespec& ts);
45     explicit TimeValue(uint32_t seconds, uint32_t nanos = 0);
46     ~TimeValue();
47
48     //------------------------------------------------------------------
49     // Operators
50     //------------------------------------------------------------------
51     const TimeValue&
52     operator=(const TimeValue& rhs);
53
54     void
55     Clear ();
56
57     uint64_t
58     GetAsNanoSecondsSinceJan1_1970() const;
59
60     uint64_t
61     GetAsMicroSecondsSinceJan1_1970() const;
62
63     uint64_t
64     GetAsSecondsSinceJan1_1970() const;
65
66     struct timespec
67     GetAsTimeSpec () const;
68
69     bool
70     IsValid () const;
71
72     void
73     OffsetWithSeconds (uint64_t sec);
74
75     void
76     OffsetWithMicroSeconds (uint64_t usec);
77
78     void
79     OffsetWithNanoSeconds (uint64_t nsec);
80
81     static TimeValue
82     Now();
83     
84     void
85     Dump (Stream *s, uint32_t width = 0) const;
86
87     /// Returns only the seconds component of the TimeValue. The nanoseconds
88     /// portion is ignored. No rounding is performed.
89     /// @brief Retrieve the seconds component
90     uint32_t seconds() const { return m_nano_seconds / NanoSecPerSec; }
91
92     /// Returns only the nanoseconds component of the TimeValue. The seconds
93     /// portion is ignored.
94     /// @brief Retrieve the nanoseconds component.
95     uint32_t nanoseconds() const { return m_nano_seconds % NanoSecPerSec; }
96
97     /// Returns only the fractional portion of the TimeValue rounded down to the
98     /// nearest microsecond (divide by one thousand).
99     /// @brief Retrieve the fractional part as microseconds;
100     uint32_t microseconds() const {
101         return (m_nano_seconds % NanoSecPerSec) / NanoSecPerMicroSec;
102     }
103
104 protected:
105     //------------------------------------------------------------------
106     // Classes that inherit from TimeValue can see and modify these
107     //------------------------------------------------------------------
108     uint64_t m_nano_seconds;
109 };
110
111 bool operator == (const TimeValue &lhs, const TimeValue &rhs);
112 bool operator != (const TimeValue &lhs, const TimeValue &rhs);
113 bool operator <  (const TimeValue &lhs, const TimeValue &rhs);
114 bool operator <= (const TimeValue &lhs, const TimeValue &rhs);
115 bool operator >  (const TimeValue &lhs, const TimeValue &rhs);
116 bool operator >= (const TimeValue &lhs, const TimeValue &rhs);
117
118 uint64_t operator -(const TimeValue &lhs, const TimeValue &rhs);
119
120 } // namespace lldb_private
121
122
123 #endif  // liblldb_TimeValue_h_