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

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