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

Side by Side Diff: base/barrier_closure.cc

Issue 1116833002: Fixed member use after destruction in BarrierClosure. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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
« no previous file with comments | « no previous file | base/barrier_closure_unittest.cc » ('j') | base/barrier_closure_unittest.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/barrier_closure.h" 5 #include "base/barrier_closure.h"
6 6
7 #include "base/atomic_ref_count.h" 7 #include "base/atomic_ref_count.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 9
10 namespace { 10 namespace {
(...skipping 10 matching lines...) Expand all
21 }; 21 };
22 22
23 BarrierInfo::BarrierInfo(int num_callbacks, const base::Closure& done_closure) 23 BarrierInfo::BarrierInfo(int num_callbacks, const base::Closure& done_closure)
24 : num_callbacks_left_(num_callbacks), 24 : num_callbacks_left_(num_callbacks),
25 done_closure_(done_closure) { 25 done_closure_(done_closure) {
26 } 26 }
27 27
28 void BarrierInfo::Run() { 28 void BarrierInfo::Run() {
29 DCHECK(!base::AtomicRefCountIsZero(&num_callbacks_left_)); 29 DCHECK(!base::AtomicRefCountIsZero(&num_callbacks_left_));
30 if (!base::AtomicRefCountDec(&num_callbacks_left_)) { 30 if (!base::AtomicRefCountDec(&num_callbacks_left_)) {
31 done_closure_.Run(); 31 base::Closure done_closure = done_closure_;
danakj 2015/04/30 17:32:55 Why no Reset still? Was it important before? There
dzhioev (left Google) 2015/04/30 20:00:54 I missed that part. Returned Reset back and added
32 done_closure_.Reset(); 32 done_closure.Run();
33 } 33 }
34 } 34 }
35 35
36 } // namespace 36 } // namespace
37 37
38 namespace base { 38 namespace base {
39 39
40 base::Closure BarrierClosure(int num_callbacks_left, 40 base::Closure BarrierClosure(int num_callbacks_left,
41 const base::Closure& done_closure) { 41 const base::Closure& done_closure) {
42 DCHECK_GE(num_callbacks_left, 0); 42 DCHECK_GE(num_callbacks_left, 0);
43 43
44 if (num_callbacks_left == 0) 44 if (num_callbacks_left == 0)
45 done_closure.Run(); 45 done_closure.Run();
46 46
47 return base::Bind(&BarrierInfo::Run, 47 return base::Bind(&BarrierInfo::Run,
48 base::Owned( 48 base::Owned(
49 new BarrierInfo(num_callbacks_left, done_closure))); 49 new BarrierInfo(num_callbacks_left, done_closure)));
50 } 50 }
51 51
52 } // namespace base 52 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/barrier_closure_unittest.cc » ('j') | base/barrier_closure_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698