]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/llvm/tools/lldb/source/Utility/TimeSpecTimeout.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / llvm / tools / lldb / source / Utility / TimeSpecTimeout.h
1 //===--------------------- TimeSpecTimeout.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 utility_TimeSpecTimeout_h_
11 #define utility_TimeSpecTimeout_h_
12
13 #include "lldb/Host/TimeValue.h"
14
15 namespace lldb_private {
16
17 class TimeSpecTimeout
18 {
19 public:
20     TimeSpecTimeout() :
21         m_infinite (false)
22     {
23         m_timespec.tv_sec = 0;
24         m_timespec.tv_nsec = 0;
25     }
26     ~TimeSpecTimeout()
27     {
28     }
29
30     //----------------------------------------------------------------------
31     /// Sets the timespec pointer correctly given a timeout relative to the
32     /// current time. This function should be called immediately prior to
33     /// calling the function you will use this timeout with since time can
34     /// elapse between when this function is called and when the timeout is
35     /// used.
36     ///
37     /// @param[in] timeout_usec
38     ///     The timeout in micro seconds. If timeout_usec is UINT32_MAX, the
39     ///     timeout should be set to INFINITE. Otherwise the current time is
40     ///     filled into the timespec and \a timeout_usec is added to the
41     ///     current time.
42     ///
43     /// @return
44     ///     If the timeout is INFINITE, then return NULL, otherwise return
45     ///     a pointer to the timespec with the appropriate timeout value.
46     //----------------------------------------------------------------------
47     const struct timespec *
48     SetAbsoluteTimeoutMircoSeconds32 (uint32_t timeout_usec);
49
50     //----------------------------------------------------------------------
51     /// Sets the timespec pointer correctly given a relative time in micro
52     /// seconds. 
53     ///
54     /// @param[in] timeout_usec
55     ///     The timeout in micro seconds. If timeout_usec is UINT32_MAX, the
56     ///     timeout should be set to INFINITE. Otherwise \a timeout_usec
57     ///     is correctly placed into the timespec.
58     ///
59     /// @return
60     ///     If the timeout is INFINITE, then return NULL, otherwise return
61     ///     a pointer to the timespec with the appropriate timeout value.
62     //----------------------------------------------------------------------
63     const struct timespec *
64     SetRelativeTimeoutMircoSeconds32 (uint32_t timeout_usec);
65
66     //----------------------------------------------------------------------
67     /// Gets the timespec pointer that is appropriate for the timeout
68     /// specified. This function should only be used after a call to
69     /// SetRelativeTimeoutXXX() functions.
70     ///
71     /// @return
72     ///     If the timeout is INFINITE, then return NULL, otherwise return
73     ///     a pointer to the timespec with the appropriate timeout value.
74     //----------------------------------------------------------------------
75     const struct timespec *
76     GetTimeSpecPtr () const
77     {
78         if (m_infinite)
79             return NULL;
80         return &m_timespec;
81     }
82     
83 protected:
84     struct timespec m_timespec;
85     bool m_infinite;
86 };
87
88 } // namespace lldb_private
89
90 #endif // #ifndef utility_TimeSpecTimeout_h_