Skip to content

Commit

Permalink
Make sure Scheduler::GetCurrent() cannot return a nullptr (#2887)
Browse files Browse the repository at this point in the history
  • Loading branch information
louwers authored Oct 4, 2024
1 parent 0ecd218 commit 4d7d5f5
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
3 changes: 2 additions & 1 deletion include/mbgl/actor/scheduler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions platform/android/MapLibreAndroid/src/cpp/jni_native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion platform/darwin/src/run_loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
6 changes: 6 additions & 0 deletions platform/windows/windows.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
7 changes: 6 additions & 1 deletion src/mbgl/actor/scheduler.cpp
Original file line number Diff line number Diff line change
@@ -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 {

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

Expand Down

0 comments on commit 4d7d5f5

Please sign in to comment.