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

Side by Side Diff: base/threading/post_task_and_reply_impl.cc

Issue 2657603004: Clear PostTaskAndReply task on the destination thread (3) (Closed)
Patch Set: reorder delete_flag check. +comment Created 3 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/threading/post_task_and_reply_impl.h" 5 #include "base/threading/post_task_and_reply_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/debug/leak_annotations.h" 10 #include "base/debug/leak_annotations.h"
(...skipping 21 matching lines...) Expand all
32 Closure task, 32 Closure task,
33 Closure reply) 33 Closure reply)
34 : sequence_checker_(), 34 : sequence_checker_(),
35 from_here_(from_here), 35 from_here_(from_here),
36 origin_task_runner_(SequencedTaskRunnerHandle::Get()), 36 origin_task_runner_(SequencedTaskRunnerHandle::Get()),
37 reply_(std::move(reply)), 37 reply_(std::move(reply)),
38 task_(std::move(task)) {} 38 task_(std::move(task)) {}
39 39
40 ~PostTaskAndReplyRelay() { 40 ~PostTaskAndReplyRelay() {
41 DCHECK(sequence_checker_.CalledOnValidSequence()); 41 DCHECK(sequence_checker_.CalledOnValidSequence());
42 task_.Reset();
43 reply_.Reset();
44 } 42 }
45 43
46 void RunTaskAndPostReply() { 44 void RunTaskAndPostReply() {
47 task_.Run(); 45 task_.Run();
46 task_.Reset();
48 origin_task_runner_->PostTask( 47 origin_task_runner_->PostTask(
49 from_here_, Bind(&PostTaskAndReplyRelay::RunReplyAndSelfDestruct, 48 from_here_, Bind(&PostTaskAndReplyRelay::RunReplyAndSelfDestruct,
50 base::Unretained(this))); 49 base::Unretained(this)));
51 } 50 }
52 51
53 private: 52 private:
54 void RunReplyAndSelfDestruct() { 53 void RunReplyAndSelfDestruct() {
55 DCHECK(sequence_checker_.CalledOnValidSequence()); 54 DCHECK(sequence_checker_.CalledOnValidSequence());
56 55
57 // Force |task_| to be released before |reply_| is to ensure that no one 56 // Ensure |task_| has already been released before |reply_| to ensure that
58 // accidentally depends on |task_| keeping one of its arguments alive while 57 // no one accidentally depends on |task_| keeping one of its arguments alive
59 // |reply_| is executing. 58 // while |reply_| is executing.
60 task_.Reset(); 59 DCHECK(!task_);
61 60
62 reply_.Run(); 61 reply_.Run();
63 62
64 // Cue mission impossible theme. 63 // Cue mission impossible theme.
65 delete this; 64 delete this;
66 } 65 }
67 66
68 const SequenceChecker sequence_checker_; 67 const SequenceChecker sequence_checker_;
69 const tracked_objects::Location from_here_; 68 const tracked_objects::Location from_here_;
70 const scoped_refptr<SequencedTaskRunner> origin_task_runner_; 69 const scoped_refptr<SequencedTaskRunner> origin_task_runner_;
(...skipping 24 matching lines...) Expand all
95 delete relay; 94 delete relay;
96 return false; 95 return false;
97 } 96 }
98 97
99 return true; 98 return true;
100 } 99 }
101 100
102 } // namespace internal 101 } // namespace internal
103 102
104 } // namespace base 103 } // namespace base
OLDNEW
« no previous file with comments | « base/message_loop/message_loop_task_runner_unittest.cc ('k') | base/threading/post_task_and_reply_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698