CppCommon  1.0.4.1
C++ Common Library
Public Member Functions | List of all members
CppCommon::NamedCriticalSection Class Reference

Named critical section synchronization primitive. More...

#include <named_critical_section.h>

Public Member Functions

 NamedCriticalSection (const std::string &name)
 Default class constructor. More...
 
 NamedCriticalSection (const NamedCriticalSection &)=delete
 
 NamedCriticalSection (NamedCriticalSection &&cs)=delete
 
 ~NamedCriticalSection ()
 
NamedCriticalSectionoperator= (const NamedCriticalSection &)=delete
 
NamedCriticalSectionoperator= (NamedCriticalSection &&cs)=delete
 
const std::string & name () const
 Get the critical section name. More...
 
bool TryLock ()
 Try to acquire critical section without block. More...
 
bool TryLockFor (const Timespan &timespan)
 Try to acquire critical section for the given timespan. More...
 
bool TryLockUntil (const UtcTimestamp &timestamp)
 Try to acquire critical section until the given timestamp. More...
 
void Lock ()
 Acquire critical section with block. More...
 
void Unlock ()
 Release critical section. More...
 

Detailed Description

Named critical section synchronization primitive.

Named critical section behaves as a simple critical section but could be shared between processes on the same machine.

Thread-safe.

See also
CriticalSection
Examples
threads_named_critical_section.cpp.

Definition at line 29 of file named_critical_section.h.

Constructor & Destructor Documentation

◆ NamedCriticalSection() [1/3]

CppCommon::NamedCriticalSection::NamedCriticalSection ( const std::string &  name)
explicit

Default class constructor.

Parameters
name- Critical section name

Definition at line 178 of file named_critical_section.cpp.

◆ NamedCriticalSection() [2/3]

CppCommon::NamedCriticalSection::NamedCriticalSection ( const NamedCriticalSection )
delete

◆ NamedCriticalSection() [3/3]

CppCommon::NamedCriticalSection::NamedCriticalSection ( NamedCriticalSection &&  cs)
delete

◆ ~NamedCriticalSection()

CppCommon::NamedCriticalSection::~NamedCriticalSection ( )

Definition at line 189 of file named_critical_section.cpp.

Member Function Documentation

◆ Lock()

void CppCommon::NamedCriticalSection::Lock ( )

Acquire critical section with block.

Will block.

Definition at line 223 of file named_critical_section.cpp.

◆ name()

const std::string & CppCommon::NamedCriticalSection::name ( ) const

Get the critical section name.

Definition at line 195 of file named_critical_section.cpp.

◆ operator=() [1/2]

NamedCriticalSection& CppCommon::NamedCriticalSection::operator= ( const NamedCriticalSection )
delete

◆ operator=() [2/2]

NamedCriticalSection& CppCommon::NamedCriticalSection::operator= ( NamedCriticalSection &&  cs)
delete

◆ TryLock()

bool CppCommon::NamedCriticalSection::TryLock ( )

Try to acquire critical section without block.

Will not block.

Returns
'true' if the critical section was successfully acquired, 'false' if the critical section is busy
Examples
threads_named_critical_section.cpp.

Definition at line 197 of file named_critical_section.cpp.

◆ TryLockFor()

bool CppCommon::NamedCriticalSection::TryLockFor ( const Timespan timespan)

Try to acquire critical section for the given timespan.

Will block for the given timespan in the worst case.

Parameters
timespan- Timespan to wait for the critical section
Returns
'true' if the critical section was successfully acquired, 'false' if the critical section is busy

Definition at line 199 of file named_critical_section.cpp.

◆ TryLockUntil()

bool CppCommon::NamedCriticalSection::TryLockUntil ( const UtcTimestamp timestamp)
inline

Try to acquire critical section until the given timestamp.

Will block until the given timestamp in the worst case.

Parameters
timestamp- Timestamp to stop wait for the critical section
Returns
'true' if the critical section was successfully acquired, 'false' if the critical section is busy

Definition at line 70 of file named_critical_section.h.

◆ Unlock()

void CppCommon::NamedCriticalSection::Unlock ( )

Release critical section.

Will not block.

Examples
threads_named_critical_section.cpp.

Definition at line 224 of file named_critical_section.cpp.


The documentation for this class was generated from the following files: