Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3548)

Unified Diff: base/threading/post_task_and_reply_impl.cc

Issue 2657603004: Clear PostTaskAndReply task on the destination thread (3) (Closed)
Patch Set: rebase Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/threading/post_task_and_reply_impl.cc
diff --git a/base/threading/post_task_and_reply_impl.cc b/base/threading/post_task_and_reply_impl.cc
index 7899f65f94bd792e3f9bd2f277a9e11595e590b7..9600369540e37a59875192b6d78c8ea7d12cc919 100644
--- a/base/threading/post_task_and_reply_impl.cc
+++ b/base/threading/post_task_and_reply_impl.cc
@@ -28,22 +28,21 @@ namespace {
class PostTaskAndReplyRelay {
public:
PostTaskAndReplyRelay(const tracked_objects::Location& from_here,
- const Closure& task,
gab 2017/01/31 19:34:59 Can this CL be focused on this change only? (i.e.
tzik 2017/02/07 08:05:35 Sure. Let me split them to a separate CL.
- const Closure& reply)
+ Closure task,
+ Closure reply)
: sequence_checker_(),
from_here_(from_here),
origin_task_runner_(SequencedTaskRunnerHandle::Get()),
- reply_(reply),
- task_(task) {}
+ reply_(std::move(reply)),
+ task_(std::move(task)) {}
~PostTaskAndReplyRelay() {
DCHECK(sequence_checker_.CalledOnValidSequence());
- task_.Reset();
- reply_.Reset();
}
void RunTaskAndPostReply() {
task_.Run();
+ task_.Reset();
origin_task_runner_->PostTask(
from_here_, Bind(&PostTaskAndReplyRelay::RunReplyAndSelfDestruct,
base::Unretained(this)));
@@ -53,10 +52,10 @@ class PostTaskAndReplyRelay {
void RunReplyAndSelfDestruct() {
DCHECK(sequence_checker_.CalledOnValidSequence());
- // Force |task_| to be released before |reply_| is to ensure that no one
+ // Ensure |task_| to be released before |reply_| is to ensure that no one
dcheng 2017/02/07 07:28:44 Nit: reword to fix some minor typos in the rest of
tzik 2017/02/07 08:05:34 Acknowledged.
tzik 2017/02/07 08:33:26 Done.
// accidentally depends on |task_| keeping one of its arguments alive while
// |reply_| is executing.
- task_.Reset();
+ DCHECK(!task_);
reply_.Run();
@@ -77,12 +76,12 @@ namespace internal {
bool PostTaskAndReplyImpl::PostTaskAndReply(
const tracked_objects::Location& from_here,
- const Closure& task,
- const Closure& reply) {
+ Closure task,
+ Closure reply) {
DCHECK(!task.is_null()) << from_here.ToString();
DCHECK(!reply.is_null()) << from_here.ToString();
PostTaskAndReplyRelay* relay =
- new PostTaskAndReplyRelay(from_here, task, reply);
+ new PostTaskAndReplyRelay(from_here, std::move(task), std::move(reply));
// PostTaskAndReplyRelay self-destructs after executing |reply|. On the flip
// side though, it is intentionally leaked if the |task| doesn't complete
// before the origin sequence stops executing tasks. Annotate |relay| as leaky

Powered by Google App Engine
This is Rietveld 408576698