summaryrefslogtreecommitdiffhomepage
path: root/compat/timer-resolution.hpp
diff options
context:
space:
mode:
authorStanisław Halik <sthalik@misaki.pl>2017-05-14 16:22:09 +0200
committerGitHub <noreply@github.com>2017-05-14 16:22:09 +0200
commit5c23666b58bb1dd4aea15c0d62a2f716d5be7f52 (patch)
treee6497e9b55c073be209ec673ef05e62bf57a2c8f /compat/timer-resolution.hpp
parent4701dd3b0c8323a11cf7d5ad09c579a9864a41bd (diff)
parentc392181211b245e74292424500265323c960c1aa (diff)
Merge branch 'unstable' into unstable
Diffstat (limited to 'compat/timer-resolution.hpp')
-rw-r--r--compat/timer-resolution.hpp45
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
{