From 8fee0f33c081d339a143306a0c82baacdac5a74c Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 8 Mar 2016 09:29:44 -0800 Subject: [PATCH] [core] Fix RunLoop::run() behavior when called a second time --- platform/default/run_loop.cpp | 1 + test/util/run_loop.cpp | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/platform/default/run_loop.cpp b/platform/default/run_loop.cpp index 76c01b80b..6230e8f1a 100644 --- a/platform/default/run_loop.cpp +++ b/platform/default/run_loop.cpp @@ -151,6 +151,7 @@ void RunLoop::push(std::shared_ptr task) { void RunLoop::run() { MBGL_VERIFY_THREAD(tid); + uv_ref(impl->holderHandle()); uv_run(impl->loop, UV_RUN_DEFAULT); } diff --git a/test/util/run_loop.cpp b/test/util/run_loop.cpp index b6e5acca0..565ce2c06 100644 --- a/test/util/run_loop.cpp +++ b/test/util/run_loop.cpp @@ -29,3 +29,24 @@ TEST(RunLoop, MultipleStop) { loop.run(); } + +TEST(RunLoop, MultipleRun) { + RunLoop loop(RunLoop::Type::New); + + Timer timer; + timer.start(mbgl::Duration::zero(), mbgl::Duration::zero(), [&] { + loop.stop(); + }); + + loop.run(); + + bool secondTimeout = false; + timer.start(mbgl::Duration::zero(), mbgl::Duration::zero(), [&] { + secondTimeout = true; + loop.stop(); + }); + + loop.run(); + + EXPECT_TRUE(secondTimeout); +}