[core] Get rid of ::unref() for Timer and AsyncTask
Not need, legacy from libuv. The RunLoop keep the main loop running until is explicitly no longer needed.
This commit is contained in:
@@ -28,6 +28,7 @@ public:
|
||||
}
|
||||
|
||||
handle()->data = this;
|
||||
uv_unref(handle());
|
||||
}
|
||||
|
||||
~Impl() {
|
||||
@@ -43,10 +44,6 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void unref() {
|
||||
uv_unref(handle());
|
||||
}
|
||||
|
||||
private:
|
||||
static void asyncCallback(UV_ASYNC_PARAMS(handle)) {
|
||||
reinterpret_cast<Impl*>(handle->data)->task();
|
||||
@@ -71,9 +68,5 @@ void AsyncTask::send() {
|
||||
impl->maySend();
|
||||
}
|
||||
|
||||
void AsyncTask::unref() {
|
||||
impl->unref();
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -177,7 +177,6 @@ OnlineFileSource::Impl::Impl(FileCache* cache_, const std::string& root)
|
||||
// loop alive; otherwise our app wouldn't terminate. After all, we only need status change
|
||||
// notifications when our app is still running.
|
||||
NetworkStatus::Subscribe(&reachability);
|
||||
reachability.unref();
|
||||
}
|
||||
|
||||
OnlineFileSource::Impl::~Impl() {
|
||||
|
||||
@@ -13,6 +13,12 @@ namespace {
|
||||
using namespace mbgl::util;
|
||||
static ThreadLocal<RunLoop>& current = *new ThreadLocal<RunLoop>;
|
||||
|
||||
#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10
|
||||
void dummyCallback(uv_async_t*, int) {};
|
||||
#else
|
||||
void dummyCallback(uv_async_t*) {};
|
||||
#endif
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace mbgl {
|
||||
@@ -56,7 +62,19 @@ RunLoop* RunLoop::Get() {
|
||||
|
||||
class RunLoop::Impl {
|
||||
public:
|
||||
void closeHolder() {
|
||||
uv_close(holderHandle(), [](uv_handle_t* h) {
|
||||
delete reinterpret_cast<uv_async_t*>(h);
|
||||
});
|
||||
}
|
||||
|
||||
uv_handle_t* holderHandle() {
|
||||
return reinterpret_cast<uv_handle_t*>(holder);
|
||||
}
|
||||
|
||||
uv_loop_t *loop = nullptr;
|
||||
uv_async_t* holder = new uv_async_t;
|
||||
|
||||
RunLoop::Type type;
|
||||
std::unique_ptr<AsyncTask> async;
|
||||
|
||||
@@ -81,6 +99,12 @@ RunLoop::RunLoop(Type type) : impl(std::make_unique<Impl>()) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Just for holding a ref to the main loop and keep
|
||||
// it alive as required by libuv.
|
||||
if (uv_async_init(impl->loop, impl->holder, dummyCallback) != 0) {
|
||||
throw std::runtime_error("Failed to initialize async.");
|
||||
}
|
||||
|
||||
impl->type = type;
|
||||
|
||||
current.set(this);
|
||||
@@ -90,6 +114,10 @@ RunLoop::RunLoop(Type type) : impl(std::make_unique<Impl>()) {
|
||||
RunLoop::~RunLoop() {
|
||||
current.set(nullptr);
|
||||
|
||||
// Close the dummy handle that we have
|
||||
// just to keep the main loop alive.
|
||||
impl->closeHolder();
|
||||
|
||||
if (impl->type == Type::Default) {
|
||||
return;
|
||||
}
|
||||
@@ -133,7 +161,7 @@ void RunLoop::runOnce() {
|
||||
}
|
||||
|
||||
void RunLoop::stop() {
|
||||
invoke([&] { impl->async->unref(); });
|
||||
invoke([&] { uv_unref(impl->holderHandle()); });
|
||||
}
|
||||
|
||||
void RunLoop::addWatch(int fd, Event event, std::function<void(int, Event)>&& callback) {
|
||||
|
||||
@@ -22,6 +22,7 @@ public:
|
||||
}
|
||||
|
||||
handle()->data = this;
|
||||
uv_unref(handle());
|
||||
}
|
||||
|
||||
~Impl() {
|
||||
@@ -44,10 +45,6 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void unref() {
|
||||
uv_unref(handle());
|
||||
}
|
||||
|
||||
private:
|
||||
static void timerCallback(UV_TIMER_PARAMS(handle)) {
|
||||
reinterpret_cast<Impl*>(handle->data)->cb();
|
||||
@@ -78,9 +75,5 @@ void Timer::stop() {
|
||||
impl->stop();
|
||||
}
|
||||
|
||||
void Timer::unref() {
|
||||
impl->unref();
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
} // namespace mbgl
|
||||
|
||||
Reference in New Issue
Block a user