Make sure Scheduler::GetCurrent() cannot return a nullptr (#2887)

This commit is contained in:
Bart Louwers
2024-10-04 12:47:58 +02:00
committed by GitHub
parent 0ecd218617
commit 4d7d5f50cf
5 changed files with 15 additions and 5 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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));
}

View File

@@ -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})

View File

@@ -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;
}