Make sure Scheduler::GetCurrent() cannot return a nullptr (#2887)
This commit is contained in:
@@ -80,7 +80,8 @@ public:
|
||||
virtual void waitForEmpty(const util::SimpleIdentity = util::SimpleIdentity::Empty) = 0;
|
||||
|
||||
/// Set/Get the current Scheduler for this thread
|
||||
static Scheduler* GetCurrent();
|
||||
/// @param init initialize if missing
|
||||
static Scheduler* GetCurrent(bool init = true);
|
||||
static void SetCurrent(Scheduler*);
|
||||
|
||||
/// Get the scheduler for asynchronous tasks. This method
|
||||
|
||||
@@ -68,8 +68,6 @@ void registerNatives(JavaVM* vm) {
|
||||
|
||||
jni::JNIEnv& env = jni::GetEnv(*vm, jni::jni_version_1_6);
|
||||
|
||||
// For the FileSource
|
||||
static mbgl::util::RunLoop mainRunLoop;
|
||||
FileSource::registerNative(env);
|
||||
|
||||
// Basic types
|
||||
|
||||
@@ -21,7 +21,7 @@ RunLoop* RunLoop::Get() {
|
||||
|
||||
RunLoop::RunLoop(Type)
|
||||
: impl(std::make_unique<Impl>()) {
|
||||
assert(!Scheduler::GetCurrent());
|
||||
assert(!Scheduler::GetCurrent(false));
|
||||
Scheduler::SetCurrent(this);
|
||||
impl->async = std::make_unique<AsyncTask>(std::bind(&RunLoop::process, this));
|
||||
}
|
||||
|
||||
@@ -266,6 +266,12 @@ target_link_libraries(
|
||||
$<IF:$<TARGET_EXISTS:libuv::uv_a>,libuv::uv_a,libuv::uv>
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
mbgl-expression-test
|
||||
PRIVATE
|
||||
$<IF:$<TARGET_EXISTS:libuv::uv_a>,libuv::uv_a,libuv::uv>
|
||||
)
|
||||
|
||||
# Disable benchmarks in CI as they run in VM environment
|
||||
if(NOT DEFINED ENV{CI})
|
||||
add_test(NAME mbgl-benchmark-runner COMMAND mbgl-benchmark-runner WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <mbgl/actor/scheduler.hpp>
|
||||
#include <mbgl/util/thread_local.hpp>
|
||||
#include <mbgl/util/thread_pool.hpp>
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -22,7 +23,11 @@ void Scheduler::SetCurrent(Scheduler* scheduler) {
|
||||
localScheduler = scheduler;
|
||||
}
|
||||
|
||||
Scheduler* Scheduler::GetCurrent() {
|
||||
Scheduler* Scheduler::GetCurrent(bool init) {
|
||||
if (!localScheduler && init) {
|
||||
thread_local util::RunLoop runLoop;
|
||||
SetCurrent(&runLoop);
|
||||
}
|
||||
return localScheduler;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user