From bd46d45ce988bfce6fc26efac2709206cde3b9d3 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Tue, 1 Oct 2024 15:23:10 +0200 Subject: [PATCH 1/6] Make sure Scheduler::GetCurrent() cannot return a nullptr --- platform/android/MapLibreAndroid/src/cpp/jni_native.cpp | 2 -- src/mbgl/actor/scheduler.cpp | 4 ++++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/platform/android/MapLibreAndroid/src/cpp/jni_native.cpp b/platform/android/MapLibreAndroid/src/cpp/jni_native.cpp index e8d7041e25b..ce343c48d23 100644 --- a/platform/android/MapLibreAndroid/src/cpp/jni_native.cpp +++ b/platform/android/MapLibreAndroid/src/cpp/jni_native.cpp @@ -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 diff --git a/src/mbgl/actor/scheduler.cpp b/src/mbgl/actor/scheduler.cpp index 515a777848e..5c5a0ba425b 100644 --- a/src/mbgl/actor/scheduler.cpp +++ b/src/mbgl/actor/scheduler.cpp @@ -1,6 +1,7 @@ #include #include #include +#include namespace mbgl { @@ -23,6 +24,9 @@ void Scheduler::SetCurrent(Scheduler* scheduler) { } Scheduler* Scheduler::GetCurrent() { + if (!localScheduler) { + thread_local util::RunLoop runLoop; + } return localScheduler; } From d1535691db5036e04ba879b142a19e5702a401ff Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Tue, 1 Oct 2024 15:38:29 +0200 Subject: [PATCH 2/6] Call SetCurrent explicitly --- src/mbgl/actor/scheduler.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mbgl/actor/scheduler.cpp b/src/mbgl/actor/scheduler.cpp index 5c5a0ba425b..bd72b723dae 100644 --- a/src/mbgl/actor/scheduler.cpp +++ b/src/mbgl/actor/scheduler.cpp @@ -26,6 +26,7 @@ void Scheduler::SetCurrent(Scheduler* scheduler) { Scheduler* Scheduler::GetCurrent() { if (!localScheduler) { thread_local util::RunLoop runLoop; + SetCurrent(&runLoop); } return localScheduler; } From 50c96a3d8ea68c6e9e3d49866627a86f7c99b139 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Tue, 1 Oct 2024 17:10:00 +0200 Subject: [PATCH 3/6] Allow passing bool to GetCurrent --- include/mbgl/actor/scheduler.hpp | 3 ++- platform/darwin/src/run_loop.cpp | 2 +- src/mbgl/actor/scheduler.cpp | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/mbgl/actor/scheduler.hpp b/include/mbgl/actor/scheduler.hpp index 69a875adbda..8b2f81f22b8 100644 --- a/include/mbgl/actor/scheduler.hpp +++ b/include/mbgl/actor/scheduler.hpp @@ -80,7 +80,8 @@ class Scheduler { 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 diff --git a/platform/darwin/src/run_loop.cpp b/platform/darwin/src/run_loop.cpp index a8619116a3a..24a93d31517 100644 --- a/platform/darwin/src/run_loop.cpp +++ b/platform/darwin/src/run_loop.cpp @@ -21,7 +21,7 @@ RunLoop* RunLoop::Get() { RunLoop::RunLoop(Type) : impl(std::make_unique()) { - assert(!Scheduler::GetCurrent()); + assert(!Scheduler::GetCurrent(false)); Scheduler::SetCurrent(this); impl->async = std::make_unique(std::bind(&RunLoop::process, this)); } diff --git a/src/mbgl/actor/scheduler.cpp b/src/mbgl/actor/scheduler.cpp index bd72b723dae..707de734ddc 100644 --- a/src/mbgl/actor/scheduler.cpp +++ b/src/mbgl/actor/scheduler.cpp @@ -23,8 +23,8 @@ void Scheduler::SetCurrent(Scheduler* scheduler) { localScheduler = scheduler; } -Scheduler* Scheduler::GetCurrent() { - if (!localScheduler) { +Scheduler* Scheduler::GetCurrent(bool init) { + if (!localScheduler && init) { thread_local util::RunLoop runLoop; SetCurrent(&runLoop); } From 0421662535b99115643caa777539f6d235dad874 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Thu, 3 Oct 2024 17:48:32 +0200 Subject: [PATCH 4/6] Try to fix linker errors on Windows --- expression-test/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/expression-test/CMakeLists.txt b/expression-test/CMakeLists.txt index e71813fac1b..75d9dddb0fa 100644 --- a/expression-test/CMakeLists.txt +++ b/expression-test/CMakeLists.txt @@ -1,4 +1,4 @@ -add_executable( +sadd_executable( mbgl-expression-test ${PROJECT_SOURCE_DIR}/expression-test/expression_test_logger.cpp ${PROJECT_SOURCE_DIR}/expression-test/expression_test_logger.hpp @@ -24,6 +24,7 @@ target_link_libraries( Mapbox::Base::Extras::args mbgl-core mbgl-compiler-options + $,libuv::uv_a,libuv::uv> ) set_property(TARGET mbgl-expression-test PROPERTY FOLDER MapLibre) From 701a4dbe7b20d99c9b0a20c419487eb734c4f0cb Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Thu, 3 Oct 2024 19:40:11 +0200 Subject: [PATCH 5/6] Update CMakeLists.txt --- expression-test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/expression-test/CMakeLists.txt b/expression-test/CMakeLists.txt index 75d9dddb0fa..e3d2703c46b 100644 --- a/expression-test/CMakeLists.txt +++ b/expression-test/CMakeLists.txt @@ -1,4 +1,4 @@ -sadd_executable( +add_executable( mbgl-expression-test ${PROJECT_SOURCE_DIR}/expression-test/expression_test_logger.cpp ${PROJECT_SOURCE_DIR}/expression-test/expression_test_logger.hpp From 7b56b650a6624b9b3d6d9ce0e30910213a30de29 Mon Sep 17 00:00:00 2001 From: Bart Louwers Date: Thu, 3 Oct 2024 20:30:42 +0200 Subject: [PATCH 6/6] Fix expression test compilation --- expression-test/CMakeLists.txt | 1 - platform/windows/windows.cmake | 6 ++++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/expression-test/CMakeLists.txt b/expression-test/CMakeLists.txt index e3d2703c46b..e71813fac1b 100644 --- a/expression-test/CMakeLists.txt +++ b/expression-test/CMakeLists.txt @@ -24,7 +24,6 @@ target_link_libraries( Mapbox::Base::Extras::args mbgl-core mbgl-compiler-options - $,libuv::uv_a,libuv::uv> ) set_property(TARGET mbgl-expression-test PROPERTY FOLDER MapLibre) diff --git a/platform/windows/windows.cmake b/platform/windows/windows.cmake index 96400553954..16736215c3b 100644 --- a/platform/windows/windows.cmake +++ b/platform/windows/windows.cmake @@ -266,6 +266,12 @@ target_link_libraries( $,libuv::uv_a,libuv::uv> ) +target_link_libraries( + mbgl-expression-test + PRIVATE + $,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})