[core] Make the BackgroundScheduler a singleton
- Do not carry it over everywhere as parameter, it is a shared instance anyway and the lifecycle is pretty much the app lifecycle from the moment we instantiate a map. - Rename to BackgroundScheduler because it is a Scheduler that will do tasks in the background, we don't make assumptions if it is a thread pool or a single thread. - Most importantly, remove the dependency from `core` on `platform`.
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
#include <mbgl/util/async_task.hpp>
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
#include <mbgl/util/default_thread_pool.hpp>
|
||||
#include <mbgl/actor/actor_ref.hpp>
|
||||
|
||||
#include <mbgl/actor/actor_ref.hpp>
|
||||
#include <mbgl/actor/scheduler.hpp>
|
||||
#include <mbgl/test/util.hpp>
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
|
||||
#include <atomic>
|
||||
#include <future>
|
||||
#include <vector>
|
||||
|
||||
using namespace mbgl;
|
||||
using namespace mbgl::util;
|
||||
|
||||
namespace {
|
||||
@@ -104,11 +105,11 @@ TEST(AsyncTask, RequestCoalescingMultithreaded) {
|
||||
unsigned count = 0, numThreads = 25;
|
||||
AsyncTask async([&count] { ++count; });
|
||||
|
||||
mbgl::ThreadPool threads(numThreads);
|
||||
auto mailbox = std::make_shared<mbgl::Mailbox>(threads);
|
||||
auto retainer = Scheduler::GetBackground();
|
||||
auto mailbox = std::make_shared<Mailbox>(*retainer);
|
||||
|
||||
TestWorker worker(&async);
|
||||
mbgl::ActorRef<TestWorker> workerRef(worker, mailbox);
|
||||
ActorRef<TestWorker> workerRef(worker, mailbox);
|
||||
|
||||
for (unsigned i = 0; i < numThreads; ++i) {
|
||||
workerRef.invoke(&TestWorker::run);
|
||||
@@ -133,11 +134,11 @@ TEST(AsyncTask, ThreadSafety) {
|
||||
|
||||
AsyncTask async([&count] { ++count; });
|
||||
|
||||
mbgl::ThreadPool threads(numThreads);
|
||||
auto mailbox = std::make_shared<mbgl::Mailbox>(threads);
|
||||
auto retainer = Scheduler::GetBackground();
|
||||
auto mailbox = std::make_shared<Mailbox>(*retainer);
|
||||
|
||||
TestWorker worker(&async);
|
||||
mbgl::ActorRef<TestWorker> workerRef(worker, mailbox);
|
||||
ActorRef<TestWorker> workerRef(worker, mailbox);
|
||||
|
||||
for (unsigned i = 0; i < numThreads; ++i) {
|
||||
// The callback runs on the worker, thus the atomic type.
|
||||
|
||||
Reference in New Issue
Block a user