diff --git a/include/mbgl/actor/scheduler.hpp b/include/mbgl/actor/scheduler.hpp index d17ccfed6d3..000235d4aca 100644 --- a/include/mbgl/actor/scheduler.hpp +++ b/include/mbgl/actor/scheduler.hpp @@ -71,7 +71,7 @@ class Scheduler { /// Wait until there's nothing pending or in process /// Must not be called from a task provided to this scheduler. - virtual void waitForEmpty(const void*) = 0; + virtual void waitForEmpty(const void* tag = nullptr) = 0; /// Set/Get the current Scheduler for this thread static Scheduler* GetCurrent(); diff --git a/test/actor/actor.test.cpp b/test/actor/actor.test.cpp index e0558f280a0..e82e45ef760 100644 --- a/test/actor/actor.test.cpp +++ b/test/actor/actor.test.cpp @@ -91,9 +91,8 @@ TEST(Actor, DestructionBlocksOnSend) { ~TestScheduler() override { EXPECT_TRUE(waited.load()); } - std::size_t waitForEmpty(Milliseconds) override { + void waitForEmpty(const void*) override { assert(false); - return 0; } void schedule(std::function&&) final { @@ -102,6 +101,11 @@ TEST(Actor, DestructionBlocksOnSend) { std::this_thread::sleep_for(1ms); waited = true; } + + void schedule(const void*, std::function&& fn) final { + schedule(std::move(fn)); + } + mapbox::base::WeakPtr makeWeakPtr() override { return weakFactory.makeWeakPtr(); } }; diff --git a/test/include/mbgl/test/vector_tile_test.hpp b/test/include/mbgl/test/vector_tile_test.hpp index 63b45aba639..ddb82544078 100644 --- a/test/include/mbgl/test/vector_tile_test.hpp +++ b/test/include/mbgl/test/vector_tile_test.hpp @@ -41,8 +41,8 @@ class VectorTileTest { ~VectorTileTest() { // Ensure that deferred releases are complete before cleaning up - EXPECT_EQ(0, loop.waitForEmpty(Milliseconds::zero())); - EXPECT_EQ(0, threadPool->waitForEmpty()); + loop.waitForEmpty(); + threadPool->waitForEmpty(); } }; diff --git a/test/util/thread.test.cpp b/test/util/thread.test.cpp index 01bfce2304b..c647dfbf1bf 100644 --- a/test/util/thread.test.cpp +++ b/test/util/thread.test.cpp @@ -343,7 +343,7 @@ TEST(Thread, PoolWait) { pool->schedule([&] { std::this_thread::sleep_for(Milliseconds(100)); }); } - EXPECT_EQ(0, pool->waitForEmpty()); + pool->waitForEmpty(); } TEST(Thread, PoolWaitRecursiveAdd) { @@ -358,7 +358,7 @@ TEST(Thread, PoolWaitRecursiveAdd) { std::this_thread::sleep_for(Milliseconds(10)); }); - EXPECT_EQ(0, pool->waitForEmpty()); + pool->waitForEmpty(); } TEST(Thread, PoolWaitAdd) { @@ -385,25 +385,10 @@ TEST(Thread, PoolWaitAdd) { // more items would be added by the sequential task if not blocked pool->schedule([&] { std::this_thread::sleep_for(Milliseconds(100)); }); - EXPECT_EQ(0, pool->waitForEmpty()); + pool->waitForEmpty(); addActive = false; - EXPECT_EQ(0, pool->waitForEmpty()); -} - -TEST(Thread, PoolWaitTimeout) { - auto pool = Scheduler::GetBackground(); - - std::mutex mutex; - { - std::lock_guard outerLock(mutex); - pool->schedule([&] { std::lock_guard innerLock(mutex); }); - - // should always time out - EXPECT_EQ(1, pool->waitForEmpty(Milliseconds(100))); - } - - EXPECT_EQ(0, pool->waitForEmpty()); + pool->waitForEmpty(); } TEST(Thread, PoolWaitException) { @@ -425,7 +410,7 @@ TEST(Thread, PoolWaitException) { } // Exceptions shouldn't cause deadlocks by, e.g., abandoning locks. - EXPECT_EQ(0, pool->waitForEmpty()); + pool->waitForEmpty(); EXPECT_EQ(threadCount, caught); } @@ -434,8 +419,8 @@ TEST(Thread, WrongThread) { auto pool = Scheduler::GetBackground(); // Asserts in debug builds, silently ignored in release. - pool->schedule([&] { EXPECT_EQ(0, pool->waitForEmpty()); }); + pool->schedule([&] { pool->waitForEmpty(); }); - EXPECT_EQ(0, pool->waitForEmpty()); + pool->waitForEmpty(); } #endif