[all] ensure runloop is the current scheduler
This commit is contained in:
committed by
Ivo van Dongen
parent
2a8cc4b3e1
commit
f4f4d13b70
@@ -1,9 +1,9 @@
|
||||
#include "file_source.hpp"
|
||||
|
||||
#include <mbgl/actor/actor.hpp>
|
||||
#include <mbgl/actor/scheduler.hpp>
|
||||
#include <mbgl/storage/resource_transform.hpp>
|
||||
#include <mbgl/util/logging.hpp>
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
|
||||
#include "asset_manager_file_source.hpp"
|
||||
#include "jni/generic_global_ref_deleter.hpp"
|
||||
@@ -45,7 +45,7 @@ void FileSource::setAPIBaseUrl(jni::JNIEnv& env, jni::String url) {
|
||||
|
||||
void FileSource::setResourceTransform(jni::JNIEnv& env, jni::Object<FileSource::ResourceTransformCallback> transformCallback) {
|
||||
if (transformCallback) {
|
||||
resourceTransform = std::make_unique<Actor<ResourceTransform>>(*util::RunLoop::Get(),
|
||||
resourceTransform = std::make_unique<Actor<ResourceTransform>>(*Scheduler::GetCurrent(),
|
||||
// Capture the ResourceTransformCallback object as a managed global into
|
||||
// the lambda. It is released automatically when we're setting a new ResourceTransform in
|
||||
// a subsequent call.
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <mbgl/util/thread_local.hpp>
|
||||
#include <mbgl/util/thread.hpp>
|
||||
#include <mbgl/util/timer.hpp>
|
||||
#include <mbgl/actor/scheduler.hpp>
|
||||
|
||||
#include <android/looper.h>
|
||||
|
||||
@@ -23,7 +24,6 @@
|
||||
namespace {
|
||||
|
||||
using namespace mbgl::util;
|
||||
static ThreadLocal<RunLoop>& current = *new ThreadLocal<RunLoop>;
|
||||
|
||||
int looperCallbackNew(int fd, int, void* data) {
|
||||
int buffer[1];
|
||||
@@ -200,19 +200,20 @@ Milliseconds RunLoop::Impl::processRunnables() {
|
||||
}
|
||||
|
||||
RunLoop* RunLoop::Get() {
|
||||
return current.get();
|
||||
assert(static_cast<RunLoop*>(Scheduler::GetCurrent()));
|
||||
return static_cast<RunLoop*>(Scheduler::GetCurrent());
|
||||
}
|
||||
|
||||
RunLoop::RunLoop(Type type) : impl(std::make_unique<Impl>(this, type)) {
|
||||
current.set(this);
|
||||
Scheduler::SetCurrent(this);
|
||||
}
|
||||
|
||||
RunLoop::~RunLoop() {
|
||||
current.set(nullptr);
|
||||
Scheduler::SetCurrent(nullptr);
|
||||
}
|
||||
|
||||
LOOP_HANDLE RunLoop::getLoopHandle() {
|
||||
return current.get()->impl.get();
|
||||
return Get()->impl.get();
|
||||
}
|
||||
|
||||
void RunLoop::push(std::shared_ptr<WorkTask> task) {
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#import "NSValue+MGLAdditions.h"
|
||||
|
||||
#include <mbgl/actor/actor.hpp>
|
||||
#include <mbgl/actor/scheduler.hpp>
|
||||
#include <mbgl/storage/resource_transform.hpp>
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
#include <mbgl/util/string.hpp>
|
||||
@@ -81,7 +82,7 @@ NSString * const MGLOfflinePackMaximumCountUserInfoKey = MGLOfflinePackUserInfoK
|
||||
- (void)setDelegate:(id<MGLOfflineStorageDelegate>)newValue {
|
||||
_delegate = newValue;
|
||||
if ([self.delegate respondsToSelector:@selector(offlineStorage:URLForResourceOfKind:withURL:)]) {
|
||||
_mbglResourceTransform = std::make_unique<mbgl::Actor<mbgl::ResourceTransform>>(*mbgl::util::RunLoop::Get(), [offlineStorage = self](auto kind_, const std::string&& url_) -> std::string {
|
||||
_mbglResourceTransform = std::make_unique<mbgl::Actor<mbgl::ResourceTransform>>(*mbgl::Scheduler::GetCurrent(), [offlineStorage = self](auto kind_, const std::string&& url_) -> std::string {
|
||||
NSURL* url =
|
||||
[NSURL URLWithString:[[NSString alloc] initWithBytes:url_.data()
|
||||
length:url_.length()
|
||||
|
||||
@@ -1,38 +1,32 @@
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
#include <mbgl/util/async_task.hpp>
|
||||
#include <mbgl/util/thread_local.hpp>
|
||||
#include <mbgl/actor/scheduler.hpp>
|
||||
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
|
||||
namespace mbgl {
|
||||
namespace util {
|
||||
|
||||
// Use a static function to avoid the static initialization order fiasco.
|
||||
static auto& current() {
|
||||
static ThreadLocal<RunLoop> tl;
|
||||
return tl;
|
||||
};
|
||||
|
||||
class RunLoop::Impl {
|
||||
public:
|
||||
std::unique_ptr<AsyncTask> async;
|
||||
};
|
||||
|
||||
RunLoop* RunLoop::Get() {
|
||||
assert(current().get());
|
||||
return current().get();
|
||||
assert(static_cast<RunLoop*>(Scheduler::GetCurrent()));
|
||||
return static_cast<RunLoop*>(Scheduler::GetCurrent());
|
||||
}
|
||||
|
||||
RunLoop::RunLoop(Type)
|
||||
: impl(std::make_unique<Impl>()) {
|
||||
assert(!current().get());
|
||||
current().set(this);
|
||||
assert(!Scheduler::GetCurrent());
|
||||
Scheduler::SetCurrent(this);
|
||||
impl->async = std::make_unique<AsyncTask>(std::bind(&RunLoop::process, this));
|
||||
}
|
||||
|
||||
RunLoop::~RunLoop() {
|
||||
assert(current().get());
|
||||
current().set(nullptr);
|
||||
assert(Scheduler::GetCurrent());
|
||||
Scheduler::SetCurrent(nullptr);
|
||||
}
|
||||
|
||||
void RunLoop::push(std::shared_ptr<WorkTask> task) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
#include <mbgl/util/async_task.hpp>
|
||||
#include <mbgl/util/thread_local.hpp>
|
||||
#include <mbgl/actor/scheduler.hpp>
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
@@ -10,9 +11,6 @@
|
||||
|
||||
namespace {
|
||||
|
||||
using namespace mbgl::util;
|
||||
static ThreadLocal<RunLoop>& current = *new ThreadLocal<RunLoop>;
|
||||
|
||||
void dummyCallback(uv_async_t*) {}
|
||||
|
||||
} // namespace
|
||||
@@ -53,7 +51,8 @@ struct Watch {
|
||||
};
|
||||
|
||||
RunLoop* RunLoop::Get() {
|
||||
return current.get();
|
||||
assert(static_cast<RunLoop*>(Scheduler::GetCurrent()));
|
||||
return static_cast<RunLoop*>(Scheduler::GetCurrent());
|
||||
}
|
||||
|
||||
class RunLoop::Impl {
|
||||
@@ -98,12 +97,12 @@ RunLoop::RunLoop(Type type) : impl(std::make_unique<Impl>()) {
|
||||
|
||||
impl->type = type;
|
||||
|
||||
current.set(this);
|
||||
Scheduler::SetCurrent(this);
|
||||
impl->async = std::make_unique<AsyncTask>(std::bind(&RunLoop::process, this));
|
||||
}
|
||||
|
||||
RunLoop::~RunLoop() {
|
||||
current.set(nullptr);
|
||||
Scheduler::SetCurrent(nullptr);
|
||||
|
||||
// Close the dummy handle that we have
|
||||
// just to keep the main loop alive.
|
||||
@@ -127,7 +126,7 @@ RunLoop::~RunLoop() {
|
||||
}
|
||||
|
||||
LOOP_HANDLE RunLoop::getLoopHandle() {
|
||||
return current.get()->impl->loop;
|
||||
return Get()->impl->loop;
|
||||
}
|
||||
|
||||
void RunLoop::push(std::shared_ptr<WorkTask> task) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "run_loop_impl.hpp"
|
||||
|
||||
#include <mbgl/util/thread_local.hpp>
|
||||
#include <mbgl/actor/scheduler.hpp>
|
||||
|
||||
#include <QCoreApplication>
|
||||
|
||||
@@ -8,13 +8,6 @@
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
|
||||
namespace {
|
||||
|
||||
using namespace mbgl::util;
|
||||
static ThreadLocal<RunLoop>& current = *new ThreadLocal<RunLoop>;
|
||||
|
||||
}
|
||||
|
||||
namespace mbgl {
|
||||
namespace util {
|
||||
|
||||
@@ -27,7 +20,8 @@ void RunLoop::Impl::onWriteEvent(int fd) {
|
||||
}
|
||||
|
||||
RunLoop* RunLoop::Get() {
|
||||
return current.get();
|
||||
assert(static_cast<RunLoop*>(Scheduler::GetCurrent()));
|
||||
return static_cast<RunLoop*>(Scheduler::GetCurrent());
|
||||
}
|
||||
|
||||
RunLoop::RunLoop(Type type) : impl(std::make_unique<Impl>()) {
|
||||
@@ -42,14 +36,14 @@ RunLoop::RunLoop(Type type) : impl(std::make_unique<Impl>()) {
|
||||
|
||||
impl->type = type;
|
||||
|
||||
current.set(this);
|
||||
Scheduler::SetCurrent(this);
|
||||
impl->async = std::make_unique<AsyncTask>(std::bind(&RunLoop::process, this));
|
||||
}
|
||||
|
||||
RunLoop::~RunLoop() {
|
||||
MBGL_VERIFY_THREAD(tid);
|
||||
|
||||
current.set(nullptr);
|
||||
Scheduler::SetCurrent(nullptr);
|
||||
}
|
||||
|
||||
LOOP_HANDLE RunLoop::getLoopHandle() {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <mbgl/util/thread_local.hpp>
|
||||
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
#include <mbgl/actor/scheduler.hpp>
|
||||
#include <mbgl/renderer/backend_scope.hpp>
|
||||
|
||||
#include <array>
|
||||
@@ -41,7 +41,7 @@ void ThreadLocal<T>::set(T* ptr) {
|
||||
impl->local.localData()[0] = ptr;
|
||||
}
|
||||
|
||||
template class ThreadLocal<RunLoop>;
|
||||
template class ThreadLocal<Scheduler>;
|
||||
template class ThreadLocal<BackendScope>;
|
||||
template class ThreadLocal<int>; // For unit tests
|
||||
|
||||
|
||||
Reference in New Issue
Block a user