diff --git a/cmake/core-files.cmake b/cmake/core-files.cmake index 47b34fcbc..90b8d97af 100644 --- a/cmake/core-files.cmake +++ b/cmake/core-files.cmake @@ -602,7 +602,5 @@ set(MBGL_CORE_FILES src/mbgl/util/utf.hpp src/mbgl/util/version.cpp src/mbgl/util/version.hpp - src/mbgl/util/work_queue.cpp - src/mbgl/util/work_queue.hpp src/mbgl/util/work_request.cpp ) diff --git a/cmake/test-files.cmake b/cmake/test-files.cmake index 9415add57..e4ffba475 100644 --- a/cmake/test-files.cmake +++ b/cmake/test-files.cmake @@ -138,5 +138,4 @@ set(MBGL_TEST_FILES test/util/timer.test.cpp test/util/token.test.cpp test/util/url.test.cpp - test/util/work_queue.test.cpp ) diff --git a/src/mbgl/text/glyph_atlas.hpp b/src/mbgl/text/glyph_atlas.hpp index f4c460153..8a672afe6 100644 --- a/src/mbgl/text/glyph_atlas.hpp +++ b/src/mbgl/text/glyph_atlas.hpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include diff --git a/src/mbgl/util/work_queue.cpp b/src/mbgl/util/work_queue.cpp deleted file mode 100644 index d0033e3ca..000000000 --- a/src/mbgl/util/work_queue.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include -#include - -#include - -namespace mbgl { -namespace util { - -WorkQueue::WorkQueue() : runLoop(RunLoop::Get()) { -} - -WorkQueue::~WorkQueue() { - assert(runLoop == RunLoop::Get()); - - // Cancel all pending AsyncRequests. - while (!queue.empty()) { - queue.pop(); - } -} - -void WorkQueue::push(std::function&& fn) { - std::lock_guard lock(queueMutex); - - auto workRequest = runLoop->invokeCancellable(std::bind(&WorkQueue::pop, this, std::move(fn))); - queue.push(std::move(workRequest)); -} - -void WorkQueue::pop(const std::function& fn) { - assert(runLoop == RunLoop::Get()); - - fn(); - - std::lock_guard lock(queueMutex); - queue.pop(); -} - -} // namespace util -} // namespace mbgl diff --git a/src/mbgl/util/work_queue.hpp b/src/mbgl/util/work_queue.hpp deleted file mode 100644 index 3f6328fb5..000000000 --- a/src/mbgl/util/work_queue.hpp +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once - -#include -#include - -#include -#include -#include -#include - -namespace mbgl { -namespace util { - -class RunLoop; - -// The WorkQueue will manage a queue of closures -// and it will make sure they get executed on the -// thread that created the WorkQueue. All pending -// works are canceled when the queue gets destructed. -class WorkQueue : private util::noncopyable { -public: - WorkQueue(); - ~WorkQueue(); - - // Push a closure to the queue. It is advised to - // only push tasks calling functions on the object - // that owns the queue to avoid use after free errors. - void push(std::function&&); - -private: - void pop(const std::function&); - - std::queue> queue; - std::mutex queueMutex; - - RunLoop* runLoop; -}; - -} // namespace util -} // namespace mbgl diff --git a/test/util/work_queue.test.cpp b/test/util/work_queue.test.cpp deleted file mode 100644 index 60c72f735..000000000 --- a/test/util/work_queue.test.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include - -#include -#include -#include - -#include - -using namespace mbgl::util; - -class TestThread { -public: - TestThread(WorkQueue* queue_) : queue(queue_) {} - - void send(std::function&& fn) { - queue->push(std::move(fn)); - } - -private: - WorkQueue* queue; -}; - -TEST(WorkQueue, push) { - RunLoop loop; - - WorkQueue queue; - Thread thread({"Test"}, &queue); - - uint8_t count = 0; - - auto endTest = [&]() { - if (++count == 4) { - loop.stop(); - } - }; - - thread.invoke(&TestThread::send, endTest); - thread.invoke(&TestThread::send, endTest); - thread.invoke(&TestThread::send, endTest); - thread.invoke(&TestThread::send, endTest); - - loop.run(); -} - -TEST(WorkQueue, cancel) { - RunLoop loop; - - WorkQueue queue; - - auto work = [&]() { - FAIL() << "Should never be called"; - }; - - queue.push(work); - queue.push(work); - queue.push(work); - queue.push(work); - queue.push(work); -}