remote_client_session_semaphore.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #pragma once
  2. #include "cc_semaphore.h"
  3. #include <util/generic/noncopyable.h>
  4. #include <library/cpp/deprecated/atomic/atomic.h>
  5. #include <util/system/condvar.h>
  6. #include <util/system/mutex.h>
  7. namespace NBus {
  8. namespace NPrivate {
  9. class TRemoteClientSessionSemaphore: public TComplexConditionSemaphore<TRemoteClientSessionSemaphore> {
  10. private:
  11. const char* const Name;
  12. TAtomicBase const Limit;
  13. TAtomic Current;
  14. TAtomic StopSignal;
  15. public:
  16. TRemoteClientSessionSemaphore(TAtomicBase limit, const char* name = "unnamed");
  17. ~TRemoteClientSessionSemaphore();
  18. TAtomicBase GetCurrent() const {
  19. return AtomicGet(Current);
  20. }
  21. void Acquire();
  22. bool TryAcquire();
  23. void Increment();
  24. void IncrementMultiple(TAtomicBase count);
  25. bool TryWait();
  26. void Release();
  27. void ReleaseMultiple(TAtomicBase count);
  28. void Stop();
  29. private:
  30. void CheckNeedToUnlock();
  31. };
  32. }
  33. }