aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/messagebus/remote_server_session_semaphore.h
blob: 32b0f27acc6d9731eb9518c86ad1eb135f7c0a52 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#pragma once

#include "cc_semaphore.h"

#include <util/generic/noncopyable.h>

namespace NBus { 
    namespace NPrivate { 
        class TRemoteServerSessionSemaphore: public TComplexConditionSemaphore<TRemoteServerSessionSemaphore> { 
        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(); 
        }; 

    } 
}