summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2015-05-01 18:13:35 -0400
committerJohn Firebaugh <john.firebaugh@gmail.com>2015-05-01 18:13:35 -0400
commit4c8f716f20bd95c9821b20a6c30ab7af35bf1497 (patch)
tree066b817b8911f1d7d1735ce61028313b7abe0064 /src
parent36f695b4112e83c1c71e05a94215bc5bd9447a90 (diff)
downloadqtlocation-mapboxgl-4c8f716f20bd95c9821b20a6c30ab7af35bf1497.tar.gz
Eliminate uv::async leak (fixes #1393)
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/util/run_loop.cpp16
-rw-r--r--src/mbgl/util/run_loop.hpp8
-rw-r--r--src/mbgl/util/thread.hpp18
3 files changed, 18 insertions, 24 deletions
diff --git a/src/mbgl/util/run_loop.cpp b/src/mbgl/util/run_loop.cpp
index fd9ad43060..7f277c9885 100644
--- a/src/mbgl/util/run_loop.cpp
+++ b/src/mbgl/util/run_loop.cpp
@@ -5,8 +5,13 @@ namespace util {
uv::tls<RunLoop> RunLoop::current;
-RunLoop::RunLoop()
- : async(*loop, std::bind(&RunLoop::process, this)) {
+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) {
@@ -24,13 +29,6 @@ void RunLoop::process() {
}
}
-void RunLoop::run() {
- assert(!current.get());
- current.set(this);
- loop.run();
- current.set(nullptr);
-}
-
void RunLoop::stop() {
invoke([&] { async.unref(); });
}
diff --git a/src/mbgl/util/run_loop.hpp b/src/mbgl/util/run_loop.hpp
index 971ad2cac7..1fc7423725 100644
--- a/src/mbgl/util/run_loop.hpp
+++ b/src/mbgl/util/run_loop.hpp
@@ -14,9 +14,9 @@ namespace util {
class RunLoop : private util::noncopyable {
public:
- RunLoop();
+ RunLoop(uv_loop_t*);
+ ~RunLoop();
- void run();
void stop();
// Invoke fn() in the runloop thread.
@@ -63,7 +63,7 @@ public:
});
}
- uv_loop_t* get() { return *loop; }
+ uv_loop_t* get() { return async.get()->loop; }
static uv::tls<RunLoop> current;
@@ -90,8 +90,6 @@ private:
Queue queue;
std::mutex mutex;
-
- uv::loop loop;
uv::async async;
};
diff --git a/src/mbgl/util/thread.hpp b/src/mbgl/util/thread.hpp
index 415bda38d8..23b89c0ab6 100644
--- a/src/mbgl/util/thread.hpp
+++ b/src/mbgl/util/thread.hpp
@@ -77,11 +77,6 @@ public:
return future.get();
}
- // Join the thread, but call the given function repeatedly in the current thread
- // while waiting for the join to finish. This should be immediately followed by
- // destroying the Thread.
- void pumpingStop(std::function<void ()>);
-
private:
Thread(const Thread&) = delete;
Thread(Thread&&) = delete;
@@ -124,21 +119,24 @@ Thread<Object>::Thread(const std::string& name, Args&&... args) {
template <class Object>
template <typename P, std::size_t... I>
void Thread<Object>::run(P&& params, index_sequence<I...>) {
- RunLoop loop_;
- loop = &loop_;
+ uv::loop l;
{
- Object object_(loop_.get(), std::get<I>(std::forward<P>(params))...);
+ Object object_(l.get(), std::get<I>(std::forward<P>(params))...);
object = &object_;
+ RunLoop loop_(l.get());
+ loop = &loop_;
+
running.set_value();
- loop_.run();
+ l.run();
+ loop = nullptr;
object = nullptr;
}
// Run the loop again to ensure that async close callbacks have been called.
- loop_.run();
+ l.run();
joinable.get_future().get();
}