remote_server_session_semaphore.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #pragma once
  2. #include "cc_semaphore.h"
  3. #include <library/cpp/deprecated/atomic/atomic.h>
  4. #include <util/generic/noncopyable.h>
  5. namespace NBus {
  6. namespace NPrivate {
  7. class TRemoteServerSessionSemaphore: public TComplexConditionSemaphore<TRemoteServerSessionSemaphore> {
  8. private:
  9. const char* const Name;
  10. TAtomicBase const LimitCount;
  11. TAtomicBase const LimitSize;
  12. TAtomic CurrentCount;
  13. TAtomic CurrentSize;
  14. TAtomic PausedByUser;
  15. TAtomic StopSignal;
  16. public:
  17. TRemoteServerSessionSemaphore(TAtomicBase limitCount, TAtomicBase limitSize, const char* name = "unnamed");
  18. ~TRemoteServerSessionSemaphore();
  19. TAtomicBase GetCurrentCount() const {
  20. return AtomicGet(CurrentCount);
  21. }
  22. TAtomicBase GetCurrentSize() const {
  23. return AtomicGet(CurrentSize);
  24. }
  25. void IncrementMultiple(TAtomicBase count, TAtomicBase size);
  26. bool TryWait();
  27. void ReleaseMultiple(TAtomicBase count, TAtomicBase size);
  28. void Stop();
  29. void PauseByUsed(bool pause);
  30. private:
  31. void CheckNeedToUnlock();
  32. };
  33. }
  34. }