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

Commit

Permalink
Add comment about a subtlety
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Jun 9, 2015
1 parent 3f6e434 commit 1c7ce5b
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/mbgl/util/run_loop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ class RunLoop : private util::noncopyable {
std::move(fn),
std::move(tuple));

// `task` is a shared pointer with ownership in the following three places:
// 1. In the `queue` of pending invocations.
// 2. In the `WorkRequest` result.
// 3. In the lambda binding of the callback to be executed on the invoking
// RunLoop. This last shared ownership is necessary in the case where
// callback execution has been scheduled (queued on the invoking RunLoop),
// but the other two places have released ownership -- i.e. the task was
// cancelled after the work is completed, but before the callback is
// executed. In this case, the lambda binding checks the cancellation flag
// and does not execute the original callback.

task->bind(callback);

withMutex([&] { queue.push(task); });
Expand Down

0 comments on commit 1c7ce5b

Please sign in to comment.