1424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 2424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// found in the LICENSE file. 4424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 5424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#ifndef BASE_BARRIER_CLOSURE_H_ 6424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#define BASE_BARRIER_CLOSURE_H_ 7424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 8424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "base/base_export.h" 9424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "base/callback_forward.h" 10424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 11424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)namespace base { 12424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 13424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// BarrierClosure executes |done_closure| after it has been invoked 14424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// |num_closures| times. 15424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// 16424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// If |num_closures| is 0, |done_closure| is executed immediately. 17424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// 18424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// BarrierClosure is thread-safe - the count of remaining closures is 19424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// maintained as a base::AtomicRefCount. |done_closure| will be run on 20424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// the thread that calls the final Run() on the returned closures. 21424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// 22424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// |done_closure| is also Reset() on the final calling thread but due to the 23424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// refcounted nature of callbacks, it is hard to know what thread resources 24424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// will be released on. 25424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)BASE_EXPORT base::Closure BarrierClosure(int num_closures, 26424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) const base::Closure& done_closure); 27424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 28424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} // namespace base 29424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 30d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#endif // BASE_BARRIER_CLOSURE_H_ 31