diff options
author | Thiago Marcos P. Santos <thiago@mapbox.com> | 2015-09-01 11:09:19 +0300 |
---|---|---|
committer | Thiago Marcos P. Santos <thiago@mapbox.com> | 2015-12-01 00:00:09 +0200 |
commit | d422c8cac4e436fb2fb1eeafbae5ed5d847e0b00 (patch) | |
tree | dd8efd2cd842820f3f13fddf40cc0039fb261363 /src | |
parent | 1d623322044c4650bb39c9224f596341a23f490f (diff) | |
download | qtlocation-mapboxgl-d422c8cac4e436fb2fb1eeafbae5ed5d847e0b00.tar.gz |
[core] Abstract main loop inside RunLoop class
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/storage/default_file_source.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/util/run_loop.cpp | 37 | ||||
-rw-r--r-- | src/mbgl/util/thread.hpp | 23 |
3 files changed, 9 insertions, 53 deletions
diff --git a/src/mbgl/storage/default_file_source.cpp b/src/mbgl/storage/default_file_source.cpp index 9e2289102e..439acd8888 100644 --- a/src/mbgl/storage/default_file_source.cpp +++ b/src/mbgl/storage/default_file_source.cpp @@ -78,7 +78,7 @@ void DefaultFileSource::cancel(const Resource& res, FileRequest* req) { // ----- Impl ----- DefaultFileSource::Impl::Impl(FileCache* cache_, const std::string& root) - : loop(util::RunLoop::getLoop()), + : loop(reinterpret_cast<uv_loop_t*>(util::RunLoop::getLoopHandle())), cache(cache_), assetRoot(root.empty() ? platform::assetRoot() : root), assetContext(AssetContextBase::createContext(loop)), diff --git a/src/mbgl/util/run_loop.cpp b/src/mbgl/util/run_loop.cpp deleted file mode 100644 index 7f277c9885..0000000000 --- a/src/mbgl/util/run_loop.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include <mbgl/util/run_loop.hpp> - -namespace mbgl { -namespace util { - -uv::tls<RunLoop> RunLoop::current; - -RunLoop::RunLoop(uv_loop_t* loop) - : async(loop, std::bind(&RunLoop::process, this)) { - current.set(this); -} - -RunLoop::~RunLoop() { - current.set(nullptr); -} - -void RunLoop::withMutex(std::function<void()>&& fn) { - std::lock_guard<std::mutex> lock(mutex); - fn(); -} - -void RunLoop::process() { - Queue queue_; - withMutex([&] { queue_.swap(queue); }); - - while (!queue_.empty()) { - (*(queue_.front()))(); - queue_.pop(); - } -} - -void RunLoop::stop() { - invoke([&] { async.unref(); }); -} - -} -} diff --git a/src/mbgl/util/thread.hpp b/src/mbgl/util/thread.hpp index d7611254cc..7924d3d4cf 100644 --- a/src/mbgl/util/thread.hpp +++ b/src/mbgl/util/thread.hpp @@ -112,26 +112,19 @@ Thread<Object>::Thread(const ThreadContext& context, Args&&... args) { template <class Object> template <typename P, std::size_t... I> void Thread<Object>::run(ThreadContext context, P&& params, std::index_sequence<I...>) { - uv::loop l; - ThreadContext::current.set(&context); - { - RunLoop loop_(l.get()); - loop = &loop_; - - Object object_(std::get<I>(std::forward<P>(params))...); - object = &object_; + RunLoop loop_(RunLoop::Type::New); + loop = &loop_; - running.set_value(); - l.run(); + Object object_(std::get<I>(std::forward<P>(params))...); + object = &object_; - loop = nullptr; - object = nullptr; - } + running.set_value(); + loop_.run(); - // Run the loop again to ensure that async close callbacks have been called. - l.run(); + loop = nullptr; + object = nullptr; ThreadContext::current.set(nullptr); |