CppCommon 1.0.5.0
C++ Common Library
Loading...
Searching...
No Matches
Public Member Functions | List of all members
CppCommon::NamedMutex Class Reference

Named mutex synchronization primitive. More...

#include <named_mutex.h>

Public Member Functions

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

Detailed Description

Named mutex synchronization primitive.

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

Thread-safe.

See also
Mutex
Examples
threads_named_mutex.cpp.

Definition at line 29 of file named_mutex.h.

Constructor & Destructor Documentation

◆ NamedMutex() [1/3]

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

Default class constructor.

Parameters
name- Mutex name

Definition at line 176 of file named_mutex.cpp.

◆ NamedMutex() [2/3]

CppCommon::NamedMutex::NamedMutex ( const NamedMutex )
delete

◆ NamedMutex() [3/3]

CppCommon::NamedMutex::NamedMutex ( NamedMutex &&  mutex)
delete

◆ ~NamedMutex()

CppCommon::NamedMutex::~NamedMutex ( )

Definition at line 187 of file named_mutex.cpp.

Member Function Documentation

◆ Lock()

void CppCommon::NamedMutex::Lock ( )

Acquire mutex with block.

Will block.

Definition at line 198 of file named_mutex.cpp.

◆ name()

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

Get the mutex name.

Definition at line 193 of file named_mutex.cpp.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

NamedMutex & CppCommon::NamedMutex::operator= ( NamedMutex &&  mutex)
delete

◆ TryLock()

bool CppCommon::NamedMutex::TryLock ( )

Try to acquire mutex without block.

Will not block.

Returns
'true' if the mutex was successfully acquired, 'false' if the mutex is busy
Examples
threads_named_mutex.cpp.

Definition at line 195 of file named_mutex.cpp.

◆ TryLockFor()

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

Try to acquire mutex for the given timespan.

Will block for the given timespan in the worst case.

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

Definition at line 196 of file named_mutex.cpp.

◆ TryLockUntil()

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

Try to acquire mutex until the given timestamp.

Will block until the given timestamp in the worst case.

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

Definition at line 70 of file named_mutex.h.

◆ Unlock()

void CppCommon::NamedMutex::Unlock ( )

Release mutex.

Will not block.

Examples
threads_named_mutex.cpp.

Definition at line 199 of file named_mutex.cpp.


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