summaryrefslogtreecommitdiff
path: root/platform/default/timer.cpp
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <thiago@mapbox.com>2015-10-27 14:27:16 +0200
committerThiago Marcos P. Santos <thiago@mapbox.com>2015-12-01 00:00:09 +0200
commit9b36c19aeb4f05e11a496d67e7388a4df0820361 (patch)
tree4167b4cd77f70d267301930be625d63d910bc3f8 /platform/default/timer.cpp
parent0d8ea6c0a238a3b76d4ac49dee89f8e62769b8fe (diff)
downloadqtlocation-mapboxgl-9b36c19aeb4f05e11a496d67e7388a4df0820361.tar.gz
[core] Introduce Timer abstraction
Diffstat (limited to 'platform/default/timer.cpp')
-rw-r--r--platform/default/timer.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/platform/default/timer.cpp b/platform/default/timer.cpp
new file mode 100644
index 0000000000..b77eaac845
--- /dev/null
+++ b/platform/default/timer.cpp
@@ -0,0 +1,40 @@
+#include <mbgl/util/timer.hpp>
+
+#include <mbgl/util/run_loop.hpp>
+#include <mbgl/util/uv_detail.hpp>
+
+namespace mbgl {
+namespace util {
+
+class Timer::Impl {
+public:
+ Impl()
+ : timer(reinterpret_cast<uv_loop_t*>(RunLoop::getLoopHandle())) {
+ }
+
+ uv::timer timer;
+};
+
+Timer::Timer()
+ : impl(std::make_unique<Impl>()) {
+}
+
+Timer::~Timer() {
+}
+
+void Timer::start(Duration timeout, Duration repeat, std::function<void()>&& cb) {
+ impl->timer.start(std::chrono::duration_cast<std::chrono::milliseconds>(timeout).count(),
+ std::chrono::duration_cast<std::chrono::milliseconds>(repeat).count(),
+ std::move(cb));
+}
+
+void Timer::stop() {
+ impl->timer.stop();
+}
+
+void Timer::unref() {
+ impl->timer.unref();
+}
+
+}
+}