Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core, ios, qt, android] Close race condition in RunLoop (issue #9620)
Browse files Browse the repository at this point in the history
Because a message we queue from the foreground may cause the background to complete, exit, and tear down the AsyncTask, we have to block queue processing until we've finished our call to AsyncTask::send().
Broadening the scope of a mutex is scary, but I audited the code of our four implementations of AsyncTask and I don't see any way this could cause a deadlock.
  • Loading branch information
ChrisLoer authored and tobrun committed Dec 6, 2017
1 parent 2a13bfd commit 966b6a5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
6 changes: 4 additions & 2 deletions platform/android/src/run_loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,10 @@ LOOP_HANDLE RunLoop::getLoopHandle() {
}

void RunLoop::push(std::shared_ptr<WorkTask> task) {
withMutex([&] { queue.push(std::move(task)); });
impl->wake();
withMutex([&] {
queue.push(std::move(task));
impl->wake();
});
}

void RunLoop::run() {
Expand Down
6 changes: 4 additions & 2 deletions platform/darwin/src/run_loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ RunLoop::~RunLoop() {
}

void RunLoop::push(std::shared_ptr<WorkTask> task) {
withMutex([&] { queue.push(std::move(task)); });
impl->async->send();
withMutex([&] {
queue.push(std::move(task));
impl->async->send();
});
}

void RunLoop::run() {
Expand Down
6 changes: 4 additions & 2 deletions platform/default/run_loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,10 @@ LOOP_HANDLE RunLoop::getLoopHandle() {
}

void RunLoop::push(std::shared_ptr<WorkTask> task) {
withMutex([&] { queue.push(std::move(task)); });
impl->async->send();
withMutex([&] {
queue.push(std::move(task));
impl->async->send();
});
}

void RunLoop::run() {
Expand Down
6 changes: 4 additions & 2 deletions platform/qt/src/run_loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ LOOP_HANDLE RunLoop::getLoopHandle() {
}

void RunLoop::push(std::shared_ptr<WorkTask> task) {
withMutex([&] { queue.push(task); });
impl->async->send();
withMutex([&] {
queue.push(std::move(task));
impl->async->send();
});
}

void RunLoop::run() {
Expand Down

0 comments on commit 966b6a5

Please sign in to comment.