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

Side by Side Diff: base/barrier_closure.cc

Issue 1647803004: Move base to DEPS (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 10 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 | « base/barrier_closure.h ('k') | base/barrier_closure_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/barrier_closure.h"
6
7 #include "base/atomic_ref_count.h"
8 #include "base/bind.h"
9
10 namespace {
11
12 // Maintains state for a BarrierClosure.
13 class BarrierInfo {
14 public:
15 BarrierInfo(int num_callbacks_left, const base::Closure& done_closure);
16 void Run();
17
18 private:
19 base::AtomicRefCount num_callbacks_left_;
20 base::Closure done_closure_;
21 };
22
23 BarrierInfo::BarrierInfo(int num_callbacks, const base::Closure& done_closure)
24 : num_callbacks_left_(num_callbacks),
25 done_closure_(done_closure) {
26 }
27
28 void BarrierInfo::Run() {
29 DCHECK(!base::AtomicRefCountIsZero(&num_callbacks_left_));
30 if (!base::AtomicRefCountDec(&num_callbacks_left_)) {
31 base::Closure done_closure = done_closure_;
32 done_closure_.Reset();
33 done_closure.Run();
34 }
35 }
36
37 } // namespace
38
39 namespace base {
40
41 base::Closure BarrierClosure(int num_callbacks_left,
42 const base::Closure& done_closure) {
43 DCHECK_GE(num_callbacks_left, 0);
44
45 if (num_callbacks_left == 0)
46 done_closure.Run();
47
48 return base::Bind(&BarrierInfo::Run,
49 base::Owned(
50 new BarrierInfo(num_callbacks_left, done_closure)));
51 }
52
53 } // namespace base
OLDNEW
« no previous file with comments | « base/barrier_closure.h ('k') | base/barrier_closure_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698