This is needed for plugging into an existing Looper because we won't call ::run() on the main thread (this is called on the Java side of the application automatically by Android). But we still need to wake up and process the events. For that we create a pipe and write to the pipe to wake up the main loop and we process events on the callback of the fd handler. Fixes #4682
58 lines
943 B
C++
58 lines
943 B
C++
#pragma once
|
|
|
|
#include "jni.hpp"
|
|
|
|
#include <mbgl/util/chrono.hpp>
|
|
#include <mbgl/util/run_loop.hpp>
|
|
|
|
#include <atomic>
|
|
#include <list>
|
|
#include <memory>
|
|
#include <mutex>
|
|
|
|
struct ALooper;
|
|
|
|
namespace mbgl {
|
|
namespace util {
|
|
|
|
class RunLoop::Impl {
|
|
public:
|
|
class Runnable {
|
|
public:
|
|
virtual ~Runnable() = default;
|
|
|
|
virtual void runTask() = 0;
|
|
virtual TimePoint dueTime() const = 0;
|
|
|
|
std::list<Runnable*>::iterator iter;
|
|
};
|
|
|
|
Impl(RunLoop*, RunLoop::Type);
|
|
~Impl();
|
|
|
|
void wake();
|
|
|
|
void addRunnable(Runnable*);
|
|
void removeRunnable(Runnable*);
|
|
void initRunnable(Runnable*);
|
|
|
|
Milliseconds processRunnables();
|
|
|
|
private:
|
|
friend RunLoop;
|
|
|
|
int fds[2];
|
|
|
|
JNIEnv *env = nullptr;
|
|
bool detach = false;
|
|
|
|
ALooper* loop = nullptr;
|
|
std::atomic<bool> running;
|
|
|
|
std::recursive_mutex mtx;
|
|
std::list<Runnable*> runnables;
|
|
};
|
|
|
|
} // namespace util
|
|
} // namespace mbgl
|