Avi Drissman | e4622aa | 2022-09-08 20:36:06 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors |
[email protected] | 285d06fc | 2013-08-24 15:00:33 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef BASE_BARRIER_CLOSURE_H_ |
| 6 | #define BASE_BARRIER_CLOSURE_H_ |
| 7 | |
| 8 | #include "base/base_export.h" |
Avi Drissman | 63e1f99 | 2023-01-13 18:54:43 | [diff] [blame] | 9 | #include "base/functional/callback.h" |
[email protected] | 285d06fc | 2013-08-24 15:00:33 | [diff] [blame] | 10 | |
| 11 | namespace base { |
| 12 | |
| 13 | // BarrierClosure executes |done_closure| after it has been invoked |
| 14 | // |num_closures| times. |
| 15 | // |
| 16 | // If |num_closures| is 0, |done_closure| is executed immediately. |
| 17 | // |
| 18 | // BarrierClosure is thread-safe - the count of remaining closures is |
| 19 | // maintained as a base::AtomicRefCount. |done_closure| will be run on |
| 20 | // the thread that calls the final Run() on the returned closures. |
| 21 | // |
tzik | 34bf605 | 2017-04-27 14:03:21 | [diff] [blame] | 22 | // |done_closure| is also cleared on the final calling thread. |
Peter Kasting | 9f9d8e3 | 2021-08-12 01:14:54 | [diff] [blame] | 23 | BASE_EXPORT RepeatingClosure BarrierClosure(size_t num_closures, |
tzik | 34bf605 | 2017-04-27 14:03:21 | [diff] [blame] | 24 | OnceClosure done_closure); |
[email protected] | 285d06fc | 2013-08-24 15:00:33 | [diff] [blame] | 25 | |
| 26 | } // namespace base |
| 27 | |
[email protected] | d5b04b83 | 2013-09-12 19:48:15 | [diff] [blame] | 28 | #endif // BASE_BARRIER_CLOSURE_H_ |