#pragma once #include "cc_semaphore.h" #include #include namespace NBus { namespace NPrivate { class TRemoteServerSessionSemaphore: public TComplexConditionSemaphore { private: const char* const Name; TAtomicBase const LimitCount; TAtomicBase const LimitSize; TAtomic CurrentCount; TAtomic CurrentSize; TAtomic PausedByUser; TAtomic StopSignal; public: TRemoteServerSessionSemaphore(TAtomicBase limitCount, TAtomicBase limitSize, const char* name = "unnamed"); ~TRemoteServerSessionSemaphore(); TAtomicBase GetCurrentCount() const { return AtomicGet(CurrentCount); } TAtomicBase GetCurrentSize() const { return AtomicGet(CurrentSize); } void IncrementMultiple(TAtomicBase count, TAtomicBase size); bool TryWait(); void ReleaseMultiple(TAtomicBase count, TAtomicBase size); void Stop(); void PauseByUsed(bool pause); private: void CheckNeedToUnlock(); }; } }