This source file includes following definitions.
- done_closure_
- Run
- BarrierClosure
#include "base/barrier_closure.h"
#include "base/atomic_ref_count.h"
#include "base/bind.h"
namespace {
class BarrierInfo {
public:
BarrierInfo(int num_callbacks_left, const base::Closure& done_closure);
void Run();
private:
base::AtomicRefCount num_callbacks_left_;
base::Closure done_closure_;
};
BarrierInfo::BarrierInfo(int num_callbacks, const base::Closure& done_closure)
: num_callbacks_left_(num_callbacks),
done_closure_(done_closure) {
}
void BarrierInfo::Run() {
DCHECK(!base::AtomicRefCountIsZero(&num_callbacks_left_));
if (!base::AtomicRefCountDec(&num_callbacks_left_)) {
done_closure_.Run();
done_closure_.Reset();
}
}
}
namespace base {
base::Closure BarrierClosure(int num_callbacks_left,
const base::Closure& done_closure) {
DCHECK(num_callbacks_left >= 0);
if (num_callbacks_left == 0)
done_closure.Run();
return base::Bind(&BarrierInfo::Run,
base::Owned(
new BarrierInfo(num_callbacks_left, done_closure)));
}
}