summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
Diffstat (limited to 'platform')
-rw-r--r--platform/android/scripts/defaults.mk1
-rw-r--r--platform/darwin/src/async_task.cpp71
-rw-r--r--platform/darwin/src/run_loop.cpp51
-rw-r--r--platform/darwin/src/timer.cpp60
-rw-r--r--platform/ios/scripts/configure.sh1
-rw-r--r--platform/ios/scripts/defaults.mk1
-rwxr-xr-xplatform/ios/scripts/package.sh3
-rw-r--r--platform/linux/scripts/defaults.mk1
-rw-r--r--platform/osx/scripts/defaults.mk1
-rwxr-xr-xplatform/osx/scripts/package.sh1
10 files changed, 186 insertions, 5 deletions
diff --git a/platform/android/scripts/defaults.mk b/platform/android/scripts/defaults.mk
index 5f049aae48..78fdd6f380 100644
--- a/platform/android/scripts/defaults.mk
+++ b/platform/android/scripts/defaults.mk
@@ -2,6 +2,7 @@ HEADLESS ?= none
PLATFORM ?= android
ASSET ?= zip
HTTP ?= android
+LOOP ?= uv
GYP_FLAVOR_SUFFIX=-android
diff --git a/platform/darwin/src/async_task.cpp b/platform/darwin/src/async_task.cpp
new file mode 100644
index 0000000000..122f95f738
--- /dev/null
+++ b/platform/darwin/src/async_task.cpp
@@ -0,0 +1,71 @@
+#include <mbgl/util/async_task.hpp>
+
+#include <CoreFoundation/CoreFoundation.h>
+
+#include <atomic>
+
+namespace mbgl {
+namespace util {
+
+class AsyncTask::Impl {
+public:
+ Impl(std::function<void()>&& fn)
+ : task(std::move(fn)),
+ loop(CFRunLoopGetCurrent()) {
+ CFRunLoopSourceContext context = {
+ 0,
+ this,
+ nullptr,
+ nullptr,
+ nullptr,
+ nullptr,
+ nullptr,
+ nullptr,
+ nullptr,
+ perform
+ };
+ source = CFRunLoopSourceCreate(kCFAllocatorDefault, 0, &context);
+ CFRunLoopAddSource(loop, source, kCFRunLoopDefaultMode);
+ }
+
+ ~Impl() {
+ CFRunLoopRemoveSource(loop, source, kCFRunLoopDefaultMode);
+ CFRelease(source);
+ }
+
+ void maySend() {
+ if (!queued.test_and_set()) {
+ CFRunLoopSourceSignal(source);
+ CFRunLoopWakeUp(loop);
+ }
+ }
+
+ void runTask() {
+ queued.clear();
+ task();
+ }
+
+private:
+ static void perform(void* info) {
+ reinterpret_cast<Impl*>(info)->runTask();
+ }
+
+ std::function<void()> task;
+ std::atomic_flag queued = ATOMIC_FLAG_INIT;
+
+ CFRunLoopRef loop;
+ CFRunLoopSourceRef source;
+};
+
+AsyncTask::AsyncTask(std::function<void()>&& fn)
+ : impl(std::make_unique<Impl>(std::move(fn))) {
+}
+
+AsyncTask::~AsyncTask() = default;
+
+void AsyncTask::send() {
+ impl->maySend();
+}
+
+} // namespace util
+} // namespace mbgl
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
diff --git a/platform/darwin/src/timer.cpp b/platform/darwin/src/timer.cpp
new file mode 100644
index 0000000000..e9e58d86c6
--- /dev/null
+++ b/platform/darwin/src/timer.cpp
@@ -0,0 +1,60 @@
+#include <mbgl/util/timer.hpp>
+
+#include <CoreFoundation/CoreFoundation.h>
+
+namespace mbgl {
+namespace util {
+
+CFTimeInterval toCFTimeInterval(Duration duration) {
+ return std::chrono::duration<CFTimeInterval>(duration).count();
+}
+
+CFAbsoluteTime toCFAbsoluteTime(Duration duration) {
+ return CFAbsoluteTimeGetCurrent() + toCFTimeInterval(duration);
+}
+
+class Timer::Impl {
+public:
+ Impl(Duration timeout, Duration repeat, std::function<void()>&& fn)
+ : task(std::move(fn)),
+ loop(CFRunLoopGetCurrent()) {
+ CFRunLoopTimerContext context = {
+ 0,
+ this,
+ nullptr,
+ nullptr,
+ nullptr
+ };
+ timer = CFRunLoopTimerCreate(kCFAllocatorDefault, toCFAbsoluteTime(timeout), toCFTimeInterval(repeat), 0, 0, perform, &context);
+ CFRunLoopAddTimer(loop, timer, kCFRunLoopDefaultMode);
+ }
+
+ ~Impl() {
+ CFRunLoopRemoveTimer(loop, timer, kCFRunLoopDefaultMode);
+ CFRelease(timer);
+ }
+
+private:
+ static void perform(CFRunLoopTimerRef, void* info) {
+ reinterpret_cast<Impl*>(info)->task();
+ }
+
+ std::function<void()> task;
+
+ CFRunLoopRef loop;
+ CFRunLoopTimerRef timer;
+};
+
+Timer::Timer() = default;
+Timer::~Timer() = default;
+
+void Timer::start(Duration timeout, Duration repeat, std::function<void()>&& cb) {
+ impl = std::make_unique<Impl>(timeout, repeat, std::move(cb));
+}
+
+void Timer::stop() {
+ impl.reset();
+}
+
+} // namespace util
+} // namespace mbgl
diff --git a/platform/ios/scripts/configure.sh b/platform/ios/scripts/configure.sh
index a62de46bef..f05d34756b 100644
--- a/platform/ios/scripts/configure.sh
+++ b/platform/ios/scripts/configure.sh
@@ -2,7 +2,6 @@
BOOST_VERSION=1.59.0
SQLITE_VERSION=system
-LIBUV_VERSION=1.7.5
ZLIB_VERSION=system
GEOJSONVT_VERSION=4.1.0
VARIANT_VERSION=1.1.0
diff --git a/platform/ios/scripts/defaults.mk b/platform/ios/scripts/defaults.mk
index ae4c815b74..9debff4ce0 100644
--- a/platform/ios/scripts/defaults.mk
+++ b/platform/ios/scripts/defaults.mk
@@ -2,6 +2,7 @@ HEADLESS = eagl
PLATFORM ?= ios
ASSET ?= fs
HTTP ?= nsurl
+LOOP ?= darwin
HOST_VERSION = all
diff --git a/platform/ios/scripts/package.sh b/platform/ios/scripts/package.sh
index 137775ef71..af03f02d80 100755
--- a/platform/ios/scripts/package.sh
+++ b/platform/ios/scripts/package.sh
@@ -6,7 +6,6 @@ set -u
NAME=Mapbox
OUTPUT=build/ios/pkg
-LIBUV_VERSION=1.7.5
BUILDTYPE=${BUILDTYPE:-Release}
BUILD_FOR_DEVICE=${BUILD_DEVICE:-true}
@@ -150,7 +149,6 @@ if [[ "${BUILD_FOR_DEVICE}" == true ]]; then
step "Assembling static framework for iOS Simulator and devices…"
mkdir -p ${OUTPUT}/static/${NAME}.framework
libtool -static -no_warning_for_no_symbols \
- `find mason_packages/ios-${IOS_SDK_VERSION} -type f -name libuv.a` \
`find mason_packages/ios-${IOS_SDK_VERSION} -type f -name libgeojsonvt.a` \
-o ${OUTPUT}/static/${NAME}.framework/${NAME} \
${LIBS[@]/#/gyp/build/${BUILDTYPE}-iphoneos/libmbgl-} \
@@ -176,7 +174,6 @@ else
step "Assembling static library for iOS Simulator…"
mkdir -p ${OUTPUT}/static/${NAME}.framework
libtool -static -no_warning_for_no_symbols \
- `find mason_packages/ios-${IOS_SDK_VERSION} -type f -name libuv.a` \
`find mason_packages/ios-${IOS_SDK_VERSION} -type f -name libgeojsonvt.a` \
-o ${OUTPUT}/static/${NAME}.framework/${NAME} \
${LIBS[@]/#/gyp/build/${BUILDTYPE}-iphonesimulator/libmbgl-}
diff --git a/platform/linux/scripts/defaults.mk b/platform/linux/scripts/defaults.mk
index c387135bb1..80f1346533 100644
--- a/platform/linux/scripts/defaults.mk
+++ b/platform/linux/scripts/defaults.mk
@@ -2,3 +2,4 @@ HEADLESS ?= glx
PLATFORM ?= linux
ASSET ?= fs
HTTP ?= curl
+LOOP ?= uv
diff --git a/platform/osx/scripts/defaults.mk b/platform/osx/scripts/defaults.mk
index 94dda854fa..be290891d6 100644
--- a/platform/osx/scripts/defaults.mk
+++ b/platform/osx/scripts/defaults.mk
@@ -2,3 +2,4 @@ HEADLESS ?= cgl
PLATFORM ?= osx
ASSET ?= fs
HTTP ?= nsurl
+LOOP ?= darwin
diff --git a/platform/osx/scripts/package.sh b/platform/osx/scripts/package.sh
index f39d730674..f4b2d0c899 100755
--- a/platform/osx/scripts/package.sh
+++ b/platform/osx/scripts/package.sh
@@ -7,7 +7,6 @@ set -u
NAME=Mapbox
OUTPUT=build/osx/pkg
OSX_SDK_VERSION=`xcrun --sdk macosx --show-sdk-version`
-LIBUV_VERSION=1.7.5
if [[ ${#} -eq 0 ]]; then # e.g. "make xpackage"
BUILDTYPE="Release"