summaryrefslogtreecommitdiffhomepage
path: root/compat/timer-resolution.hpp
blob: 8c18a6002534873dce777bd20bd28bb4c52008c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#pragma once

#if defined _WIN32
#   include "export.hpp"

#include <type_traits>

namespace timer_impl
{

// cf. https://msdn.microsoft.com/en-us/library/windows/desktop/aa383751%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
// for NTSTATUS, see http://stackoverflow.com/questions/3378622/how-to-understand-the-ntstatus-nt-success-typedef-in-windows-ddk

using ulong_ = unsigned long;
using long_ = long;
using byte_ = unsigned char;
using boolean_ = byte_;

using true_ = std::integral_constant<int, 1>;

using fail_ = std::integral_constant<byte_, byte_(-1)>;

// cf. http://stackoverflow.com/questions/3378622/how-to-understand-the-ntstatus-nt-success-typedef-in-windows-ddk

// typedef __success(return >= 0) LONG NTSTATUS;

// __success(expr) T f() :  indicates whether function f succeeded or
// not. If is true at exit, all the function's guarantees (as given
// by other annotations) must hold. If is false at exit, the caller
// should not expect any of the function's guarantees to hold. If not used,
// the function must always satisfy its guarantees. Added automatically to
// functions that indicate success in standard ways, such as by returning an
// HRESULT.

using ntstatus_ = long_;

// finally what we want
// this is equivalent to typedef syntax

using funptr_NtSetTimerResolution = ntstatus_ (__stdcall *)(ulong_, boolean_, ulong_*);

// RAII wrapper

class OTR_COMPAT_EXPORT timer_resolution final
{
    ulong_ old_value;

public:
    timer_resolution(int msecs);
    ~timer_resolution();
};

}

using timer_impl::timer_resolution;

#else
struct timer_resolution final
{
    inline timer_resolution(int) {}
};
#endif