#include #include "cc_semaphore.h" #include namespace { struct TTestSemaphore: public TComplexConditionSemaphore { TAtomic Current; TTestSemaphore() : Current(0) { } bool TryWait() { return AtomicGet(Current) > 0; } void Aquire() { Wait(); AtomicDecrement(Current); } void Release() { AtomicIncrement(Current); Updated(); } }; } Y_UNIT_TEST_SUITE(TComplexConditionSemaphore) { Y_UNIT_TEST(Simple) { TTestSemaphore sema; UNIT_ASSERT(!sema.TryWait()); sema.Release(); UNIT_ASSERT(sema.TryWait()); sema.Release(); UNIT_ASSERT(sema.TryWait()); sema.Aquire(); UNIT_ASSERT(sema.TryWait()); sema.Aquire(); UNIT_ASSERT(!sema.TryWait()); } }