diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2017-05-06 10:50:21 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2017-05-10 11:19:22 +0200 |
commit | 5c3c5a01285245ec046a8203dd7064fad45a02fe (patch) | |
tree | 978c4052f802655c0becc7692cfd03886fb89622 /compat/timer-resolution.hpp | |
parent | 8faea32f863988c6d55355aaf64f890923a5da5d (diff) |
compat/timer-resolution: don't include windows.h in header
Diffstat (limited to 'compat/timer-resolution.hpp')
-rw-r--r-- | compat/timer-resolution.hpp | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/compat/timer-resolution.hpp b/compat/timer-resolution.hpp index 5db877c0..8c18a600 100644 --- a/compat/timer-resolution.hpp +++ b/compat/timer-resolution.hpp @@ -3,14 +3,57 @@ #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 { - unsigned long old_value; + ulong_ old_value; public: timer_resolution(int msecs); ~timer_resolution(); }; + +} + +using timer_impl::timer_resolution; + #else struct timer_resolution final { |