[all] ensure runloop is the current scheduler
This commit is contained in:
committed by
Ivo van Dongen
parent
2a8cc4b3e1
commit
f4f4d13b70
@@ -1,38 +1,32 @@
|
||||
#include <mbgl/util/run_loop.hpp>
|
||||
#include <mbgl/util/async_task.hpp>
|
||||
#include <mbgl/util/thread_local.hpp>
|
||||
#include <mbgl/actor/scheduler.hpp>
|
||||
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
|
||||
namespace mbgl {
|
||||
namespace util {
|
||||
|
||||
// Use a static function to avoid the static initialization order fiasco.
|
||||
static auto& current() {
|
||||
static ThreadLocal<RunLoop> tl;
|
||||
return tl;
|
||||
};
|
||||
|
||||
class RunLoop::Impl {
|
||||
public:
|
||||
std::unique_ptr<AsyncTask> async;
|
||||
};
|
||||
|
||||
RunLoop* RunLoop::Get() {
|
||||
assert(current().get());
|
||||
return current().get();
|
||||
assert(static_cast<RunLoop*>(Scheduler::GetCurrent()));
|
||||
return static_cast<RunLoop*>(Scheduler::GetCurrent());
|
||||
}
|
||||
|
||||
RunLoop::RunLoop(Type)
|
||||
: impl(std::make_unique<Impl>()) {
|
||||
assert(!current().get());
|
||||
current().set(this);
|
||||
assert(!Scheduler::GetCurrent());
|
||||
Scheduler::SetCurrent(this);
|
||||
impl->async = std::make_unique<AsyncTask>(std::bind(&RunLoop::process, this));
|
||||
}
|
||||
|
||||
RunLoop::~RunLoop() {
|
||||
assert(current().get());
|
||||
current().set(nullptr);
|
||||
assert(Scheduler::GetCurrent());
|
||||
Scheduler::SetCurrent(nullptr);
|
||||
}
|
||||
|
||||
void RunLoop::push(std::shared_ptr<WorkTask> task) {
|
||||
|
||||
Reference in New Issue
Block a user