#pragma once #include #include class TCountDownLatch { private: TAtomic Current; TSystemEvent EventObject; public: TCountDownLatch(unsigned initial) : Current(initial) { } void CountDown() { if (AtomicDecrement(Current) == 0) { EventObject.Signal(); } } void Await() { EventObject.Wait(); } bool Await(TDuration timeout) { return EventObject.WaitT(timeout); } };