summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2015-11-18 17:40:26 -0800
committerThiago Marcos P. Santos <thiago@mapbox.com>2015-12-01 11:49:02 +0200
commit1c63f98f6df6a8b1a5db2cfb9e0d0bedba931b07 (patch)
tree2a0a38ce4f17d687ba093e880e8b34f06306e6f0
parentf2553fff8926e78fdc00119efec48933f542ada1 (diff)
downloadqtlocation-mapboxgl-1c63f98f6df6a8b1a5db2cfb9e0d0bedba931b07.tar.gz
[core] Expose fewer RunLoop implementation details in header
-rw-r--r--include/mbgl/util/run_loop.hpp23
-rw-r--r--platform/default/http_request_curl.cpp2
-rw-r--r--platform/default/run_loop.cpp22
-rw-r--r--src/mbgl/util/work_queue.cpp3
4 files changed, 26 insertions, 24 deletions
diff --git a/include/mbgl/util/run_loop.hpp b/include/mbgl/util/run_loop.hpp
index 8a2855e94b..122f90c3d7 100644
--- a/include/mbgl/util/run_loop.hpp
+++ b/include/mbgl/util/run_loop.hpp
@@ -1,11 +1,9 @@
#ifndef MBGL_UTIL_RUN_LOOP
#define MBGL_UTIL_RUN_LOOP
-#include <mbgl/util/async_task.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/work_task.hpp>
#include <mbgl/util/work_request.hpp>
-#include <mbgl/util/uv.hpp>
#include <functional>
#include <utility>
@@ -28,10 +26,7 @@ public:
RunLoop(Type type = Type::Default);
~RunLoop();
- static RunLoop* Get() {
- return current.get();
- }
-
+ static RunLoop* Get();
static LOOP_HANDLE getLoopHandle();
void run();
@@ -46,8 +41,7 @@ public:
std::move(fn),
std::move(tuple));
- withMutex([&] { queue.push(task); });
- async->send();
+ push(task);
}
// Post the cancellable work fn(args...) to this RunLoop.
@@ -63,8 +57,7 @@ public:
std::move(tuple),
flag);
- withMutex([&] { queue.push(task); });
- async->send();
+ push(task);
return std::make_unique<WorkRequest>(task);
}
@@ -81,7 +74,7 @@ public:
// because if the request was cancelled, then R might have been destroyed. L2 needs to check
// the flag because the request may have been cancelled after L2 was invoked but before it
// began executing.
- auto after = [flag, current = RunLoop::current.get(), callback1 = std::move(callback)] (auto&&... results1) {
+ auto after = [flag, current = RunLoop::Get(), callback1 = std::move(callback)] (auto&&... results1) {
if (!*flag) {
current->invoke([flag, callback2 = std::move(callback1)] (auto&&... results2) {
if (!*flag) {
@@ -97,8 +90,7 @@ public:
std::move(tuple),
flag);
- withMutex([&] { queue.push(task); });
- async->send();
+ push(task);
return std::make_unique<WorkRequest>(task);
}
@@ -149,6 +141,8 @@ private:
using Queue = std::queue<std::shared_ptr<WorkTask>>;
+ void push(std::shared_ptr<WorkTask>);
+
void withMutex(std::function<void()>&& fn) {
std::lock_guard<std::mutex> lock(mutex);
fn();
@@ -166,12 +160,9 @@ private:
Queue queue;
std::mutex mutex;
- std::unique_ptr<AsyncTask> async;
class Impl;
std::unique_ptr<Impl> impl;
-
- static uv::tls<RunLoop> current;
};
}
diff --git a/platform/default/http_request_curl.cpp b/platform/default/http_request_curl.cpp
index ad8e37bc2f..18d6d9d62a 100644
--- a/platform/default/http_request_curl.cpp
+++ b/platform/default/http_request_curl.cpp
@@ -9,9 +9,9 @@
#include <mbgl/util/run_loop.hpp>
#include <mbgl/util/string.hpp>
#include <mbgl/util/timer.hpp>
+#include <mbgl/util/uv.hpp>
#include <curl/curl.h>
-#include <uv.h>
#ifdef __ANDROID__
#include <mbgl/android/jni.hpp>
diff --git a/platform/default/run_loop.cpp b/platform/default/run_loop.cpp
index 7c3a74f2cb..a0262364ca 100644
--- a/platform/default/run_loop.cpp
+++ b/platform/default/run_loop.cpp
@@ -1,11 +1,15 @@
#include <mbgl/util/run_loop.hpp>
-
-#include <uv.h>
+#include <mbgl/util/async_task.hpp>
+#include <mbgl/util/uv.hpp>
namespace mbgl {
namespace util {
-uv::tls<RunLoop> RunLoop::current;
+static uv::tls<RunLoop> current;
+
+RunLoop* RunLoop::Get() {
+ return current.get();
+}
class RunLoop::Impl {
public:
@@ -13,6 +17,7 @@ public:
uv_loop_t *loop;
RunLoop::Type type;
+ std::unique_ptr<AsyncTask> async;
};
RunLoop::RunLoop(Type type) : impl(std::make_unique<Impl>()) {
@@ -36,7 +41,7 @@ RunLoop::RunLoop(Type type) : impl(std::make_unique<Impl>()) {
impl->type = type;
current.set(this);
- async = std::make_unique<AsyncTask>(std::bind(&RunLoop::process, this));
+ impl->async = std::make_unique<AsyncTask>(std::bind(&RunLoop::process, this));
}
RunLoop::~RunLoop() {
@@ -50,7 +55,7 @@ RunLoop::~RunLoop() {
// close callbacks have been called. Not needed
// for the default main loop because it is only
// closed when the application exits.
- async.reset();
+ impl->async.reset();
runOnce();
#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10
@@ -67,6 +72,11 @@ LOOP_HANDLE RunLoop::getLoopHandle() {
return current.get()->impl->loop;
}
+void RunLoop::push(std::shared_ptr<WorkTask> task) {
+ withMutex([&] { queue.push(task); });
+ impl->async->send();
+}
+
void RunLoop::run() {
uv_run(impl->loop, UV_RUN_DEFAULT);
}
@@ -76,7 +86,7 @@ void RunLoop::runOnce() {
}
void RunLoop::stop() {
- invoke([&] { async->unref(); });
+ invoke([&] { impl->async->unref(); });
}
}
diff --git a/src/mbgl/util/work_queue.cpp b/src/mbgl/util/work_queue.cpp
index 7e1406bba0..ee8e128829 100644
--- a/src/mbgl/util/work_queue.cpp
+++ b/src/mbgl/util/work_queue.cpp
@@ -1,7 +1,8 @@
#include <mbgl/util/work_queue.hpp>
-
#include <mbgl/util/run_loop.hpp>
+#include <cassert>
+
namespace mbgl {
namespace util {