diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-02-16 12:52:25 -0800 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-04-01 09:26:54 -0700 |
commit | 879382f72405edd1840d2f37744bcba49131859a (patch) | |
tree | 4f632c8973d1c5539437e790edb471090339b533 /platform/darwin/src/run_loop.cpp | |
parent | 7e9a4f15c5082dfe5987e1dcbb4b816f04068a60 (diff) | |
download | qtlocation-mapboxgl-879382f72405edd1840d2f37744bcba49131859a.tar.gz |
[ios, osx] Replace libuv with native implementations
Diffstat (limited to 'platform/darwin/src/run_loop.cpp')
-rw-r--r-- | platform/darwin/src/run_loop.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/platform/darwin/src/run_loop.cpp b/platform/darwin/src/run_loop.cpp new file mode 100644 index 0000000000..6e9a1c50b0 --- /dev/null +++ b/platform/darwin/src/run_loop.cpp @@ -0,0 +1,51 @@ +#include <mbgl/util/run_loop.hpp> +#include <mbgl/util/async_task.hpp> +#include <mbgl/util/thread_local.hpp> + +#include <CoreFoundation/CoreFoundation.h> + +namespace mbgl { +namespace util { + +static ThreadLocal<RunLoop>& current = *new ThreadLocal<RunLoop>; +static RunLoop mainRunLoop; + +class RunLoop::Impl { +public: + std::unique_ptr<AsyncTask> async; +}; + +RunLoop* RunLoop::Get() { + assert(current.get()); + return current.get(); +} + +RunLoop::RunLoop(Type) + : impl(std::make_unique<Impl>()) { + current.set(this); + impl->async = std::make_unique<AsyncTask>(std::bind(&RunLoop::process, this)); +} + +RunLoop::~RunLoop() { + current.set(nullptr); +} + +void RunLoop::push(std::shared_ptr<WorkTask> task) { + withMutex([&] { queue.push(std::move(task)); }); + impl->async->send(); +} + +void RunLoop::run() { + CFRunLoopRun(); +} + +void RunLoop::runOnce() { + CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, false); +} + +void RunLoop::stop() { + invoke([&] { CFRunLoopStop(CFRunLoopGetCurrent()); }); +} + +} // namespace util +} // namespace mbgl |