aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/messagebus/remote_client_session_semaphore.h
blob: 955440b25f3176c0eb5575af8519db3a0e3798f8 (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>
#include <util/system/atomic.h>
#include <util/system/condvar.h>
#include <util/system/mutex.h>

namespace NBus { 
    namespace NPrivate { 
        class TRemoteClientSessionSemaphore: public TComplexConditionSemaphore<TRemoteClientSessionSemaphore> { 
        private: 
            const char* const Name; 

            TAtomicBase const Limit; 
            TAtomic Current; 
            TAtomic StopSignal; 

        public: 
            TRemoteClientSessionSemaphore(TAtomicBase limit, const char* name = "unnamed"); 
            ~TRemoteClientSessionSemaphore(); 

            TAtomicBase GetCurrent() const { 
                return AtomicGet(Current); 
            } 

            void Acquire(); 
            bool TryAcquire(); 
            void Increment(); 
            void IncrementMultiple(TAtomicBase count); 
            bool TryWait(); 
            void Release(); 
            void ReleaseMultiple(TAtomicBase count); 
            void Stop(); 

        private: 
            void CheckNeedToUnlock(); 
        }; 

    } 
}