diff options
author | Thiago Marcos P. Santos <tmpsantos@gmail.com> | 2017-06-14 16:52:39 +0300 |
---|---|---|
committer | Thiago Marcos P. Santos <tmpsantos@gmail.com> | 2017-06-21 14:30:09 +0300 |
commit | 495f06ac4dd8595cd388eb72fbd98ba7d8ddc3b6 (patch) | |
tree | a695d93b45f2e86d4e140be8a14a6d788584e994 /test/storage | |
parent | 999de53f11a5dbddcd0217326ad17b9d8a8de791 (diff) | |
download | qtlocation-mapboxgl-495f06ac4dd8595cd388eb72fbd98ba7d8ddc3b6.tar.gz |
[core] Convert AssetFileSource to ThreadedObject
Diffstat (limited to 'test/storage')
-rw-r--r-- | test/storage/asset_file_source.test.cpp | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/test/storage/asset_file_source.test.cpp b/test/storage/asset_file_source.test.cpp index 010a2c9dc7..5dd03256dc 100644 --- a/test/storage/asset_file_source.test.cpp +++ b/test/storage/asset_file_source.test.cpp @@ -2,9 +2,11 @@ #include <mbgl/util/platform.hpp> #include <mbgl/util/chrono.hpp> #include <mbgl/util/run_loop.hpp> -#include <mbgl/util/thread.hpp> +#include <mbgl/util/threaded_object.hpp> +#include <mbgl/actor/actor_ref.hpp> #include <gtest/gtest.h> +#include <atomic> using namespace mbgl; @@ -20,16 +22,11 @@ TEST(AssetFileSource, Load) { #else unsigned numThreads = 50; #endif - - auto callback = [&] { - if (!--numThreads) { - loop.stop(); - } - }; + std::atomic_uint completed(numThreads); class TestWorker { public: - TestWorker(mbgl::AssetFileSource* fs_) : fs(fs_) {} + TestWorker(ActorRef<TestWorker>, mbgl::AssetFileSource* fs_) : fs(fs_) {} void run(std::function<void()> endCallback) { const std::string asset("asset://nonempty"); @@ -59,17 +56,13 @@ TEST(AssetFileSource, Load) { std::function<void(mbgl::Response)> requestCallback; }; - std::vector<std::unique_ptr<util::Thread<TestWorker>>> threads; - std::vector<std::unique_ptr<mbgl::AsyncRequest>> requests; - util::ThreadContext context = { "Test" }; + std::vector<std::unique_ptr<util::ThreadedObject<TestWorker>>> threads; for (unsigned i = 0; i < numThreads; ++i) { - std::unique_ptr<util::Thread<TestWorker>> thread = - std::make_unique<util::Thread<TestWorker>>(context, &fs); - - requests.push_back( - thread->invokeWithCallback(&TestWorker::run, callback)); + std::unique_ptr<util::ThreadedObject<TestWorker>> thread = + std::make_unique<util::ThreadedObject<TestWorker>>("Test", &fs); + thread->actor().invoke(&TestWorker::run, [&] { if (!--completed) loop.stop(); }); threads.push_back(std::move(thread)); } |