summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2017-06-10 15:58:11 +0200
committerStanislaw Halik <sthalik@misaki.pl>2017-06-10 15:58:11 +0200
commiteee281654a9a014de315589a76bca67c8b13184a (patch)
tree375792c38524cf016c3c53acd63622386dffe848
parent39c79af233bb5213701f54e779a3554fa2abe183 (diff)
timer-resolution: remove
-rw-r--r--compat/timer-resolution.cpp111
-rw-r--r--compat/timer-resolution.hpp59
-rw-r--r--logic/tracker.cpp9
3 files changed, 0 insertions, 179 deletions
diff --git a/compat/timer-resolution.cpp b/compat/timer-resolution.cpp
deleted file mode 100644
index eece39e9..00000000
--- a/compat/timer-resolution.cpp
+++ /dev/null
@@ -1,111 +0,0 @@
-/* Copyright (c) 2017 Stanislaw Halik <sthalik@misaki.pl>
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- */
-
-#ifdef _WIN32
-
-#include "timer-resolution.hpp"
-#include "time.hpp"
-#include "compat/util.hpp"
-
-#include <utility>
-
-#include <QLibrary>
-#include <QDebug>
-
-#include <windows.h>
-
-using namespace time_units;
-using namespace timer_impl;
-
-static funptr_NtSetTimerResolution init_timer_resolution_funptr()
-{
- static QLibrary ntdll;
- ntdll.setLoadHints(QLibrary::PreventUnloadHint);
- ntdll.setFileName("ntdll.dll");
- const bool load = ntdll.load();
- if (!load)
- {
- qDebug() << "can't load ntdll:" << ntdll.errorString();
- return nullptr;
- }
-
- auto ret = reinterpret_cast<funptr_NtSetTimerResolution>(ntdll.resolve("NtSetTimerResolution"));
- if (ret == nullptr)
- {
- qDebug() << "can't find NtSetTimerResolution in ntdll:" << ntdll.errorString();
- return nullptr;
- }
-
- return ret;
-}
-
-static funptr_NtSetTimerResolution get_funptr()
-{
- // starting with C++11 static initializers are fully
- // thread-safe and run the first time function is called
-
- // cf. http://stackoverflow.com/questions/8102125/is-local-static-variable-initialization-thread-safe-in-c11
-
- static auto ret = init_timer_resolution_funptr();
- return ret;
-}
-
-timer_resolution::timer_resolution()
-{
- for (int k = 14; k > 0; k--)
- if (unlikely(timeEndPeriod(k) == 0))
- {
- qDebug() << "removed mm timer for" << k << "ms";
- k++;
- }
-
- static funptr_NtSetTimerResolution set_timer_res = get_funptr();
-
- // hundredth of a nanosecond
- //const ulong_ value = msecs * ulong_(10000);
-
- const ulong_ value = 156250; // default win32 timer length
- ntstatus_ res;
- ulong_ old_value = fail_();
-
- res = set_timer_res(value, true_(), &old_value);
-
- if (unlikely(res != 0))
- {
- old_value = fail_();
- qDebug() << "NtSetTimerResolution erred with" << res;
- return;
- }
-
- if (likely(std::abs(long(old_value) - long(value)) < 10000))
- return;
-
- // see if it stuck
-
- ulong_ old_value_ = fail_();
-
- res = set_timer_res(value, true_(), &old_value_);
- if (unlikely(res != 0))
- {
- old_value = fail_();
- qDebug() << "NtSetTimerResolution check erred with" << res;
- return;
- }
-
- if (old_value_ != old_value)
- {
- using t = long long;
-
- qDebug() << "NtSetTimerResolution:"
- << "old value didn't stick"
- << "current resolution" << time_cast<ms>(ns(t(old_value_) * t(100))).count() << "ms";
- old_value = fail_();
- return;
- }
-}
-
-#endif
diff --git a/compat/timer-resolution.hpp b/compat/timer-resolution.hpp
deleted file mode 100644
index 8f1d4bc7..00000000
--- a/compat/timer-resolution.hpp
+++ /dev/null
@@ -1,59 +0,0 @@
-#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
-{
-public:
- timer_resolution();
-#if 0
- ~timer_resolution();
-#endif
-};
-
-}
-
-using timer_impl::timer_resolution;
-
-#else
-# error "this is win32-only header"
-#endif
diff --git a/logic/tracker.cpp b/logic/tracker.cpp
index 08d88c38..87706293 100644
--- a/logic/tracker.cpp
+++ b/logic/tracker.cpp
@@ -16,10 +16,6 @@
#include "compat/sleep.hpp"
#include "compat/util.hpp"
-#if defined _WIN32
-# include "compat/timer-resolution.hpp"
-#endif
-
#include "tracker.h"
#include <cmath>
@@ -387,11 +383,6 @@ void Tracker::run()
t.start();
-#if defined _WIN32
- timer_resolution res;
- (void) res;
-#endif
-
while (!get(f_should_quit))
{
logic();