summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-04-12 12:00:11 -0700
committerKonstantin Käfer <mail@kkaefer.com>2016-04-12 12:46:59 -0700
commit618b9f1dbff9c3a13c886b0edd949b7c6533fc5c (patch)
treea353ca0b088560e2fb000e6cfe2163bf4d70bf04
parent23a0e2a84e6c1c9d7d861e00d5160ca09313e707 (diff)
downloadqtlocation-mapboxgl-618b9f1dbff9c3a13c886b0edd949b7c6533fc5c.tar.gz
[darwin] use CFRunLoopSourceInvalidate() to also cancel any pending AsyncTask invocations
-rw-r--r--platform/darwin/src/async_task.cpp2
-rw-r--r--test/util/async_task.cpp27
2 files changed, 28 insertions, 1 deletions
diff --git a/platform/darwin/src/async_task.cpp b/platform/darwin/src/async_task.cpp
index 122f95f738..513629726b 100644
--- a/platform/darwin/src/async_task.cpp
+++ b/platform/darwin/src/async_task.cpp
@@ -29,7 +29,7 @@ public:
}
~Impl() {
- CFRunLoopRemoveSource(loop, source, kCFRunLoopDefaultMode);
+ CFRunLoopSourceInvalidate(source);
CFRelease(source);
}
diff --git a/test/util/async_task.cpp b/test/util/async_task.cpp
index 9d36230472..5fd890ad9e 100644
--- a/test/util/async_task.cpp
+++ b/test/util/async_task.cpp
@@ -64,6 +64,33 @@ TEST(AsyncTask, DestroyShouldNotRunQueue) {
EXPECT_EQ(count, 0);
}
+TEST(AsyncTask, DestroyAfterSignaling) {
+ RunLoop loop;
+
+ // We're creating two tasks and signal both of them; the one that gets fired first destroys
+ // the other one. Make sure that the second one we destroyed doesn't fire.
+
+ std::unique_ptr<AsyncTask> task1, task2;
+
+ task1 = std::make_unique<AsyncTask>([&] {
+ task2.reset();
+ if (!task1) {
+ FAIL() << "Task was destroyed but invoked anyway";
+ }
+ });
+ task2 = std::make_unique<AsyncTask>([&] {
+ task1.reset();
+ if (!task2) {
+ FAIL() << "Task was destroyed but invoked anyway";
+ }
+ });
+
+ task1->send();
+ task2->send();
+
+ loop.runOnce();
+}
+
TEST(AsyncTask, RequestCoalescingMultithreaded) {
RunLoop loop;