Ocean
Ocean::SharedLock Class Reference

This class implements a lock shared over individual processes (a system-wide lock). More...

Public Member Functions

 SharedLock ()=default
 Creates an invalid shared lock object. More...
 
 SharedLock (const std::wstring &name)
 Creates a new shared lock object by a system unique name of this lock. More...
 
 SharedLock (const SharedLock &sharedLock)=delete
 Disabled copy constructor. More...
 
 ~SharedLock ()
 Destructs a shared lock object. More...
 
const std::wstring & name () const
 Returns the system wide unique name of this lock. More...
 
void lock ()
 Looks the mutex. More...
 
bool tryLock ()
 Tries to lock the mutex. More...
 
void unlock ()
 Unlocks the mutex. More...
 
bool isValid () const
 Returns whether this object is valid and can be used correctly. More...
 
 operator bool () const
 Returns whether this object is valid and can be used correctly. More...
 
SharedLockoperator= (const SharedLock &sharedLock)=delete
 Disabled assign operator. More...
 

Private Member Functions

bool createSemaphore ()
 Creates the semaphore object of this lock. More...
 

Private Attributes

std::wstring name_
 System wide unique name. More...
 
Lock localLock_
 Local lock object. More...
 
unsigned int localCounter_ = 0u
 Local lock counter. More...
 
void * handle_ = nullptr
 Handle of the mutex. More...
 

Detailed Description

This class implements a lock shared over individual processes (a system-wide lock).

See also
ScopedSharedLock, SharedMemory.

Constructor & Destructor Documentation

◆ SharedLock() [1/3]

Ocean::SharedLock::SharedLock ( )
default

Creates an invalid shared lock object.

◆ SharedLock() [2/3]

Ocean::SharedLock::SharedLock ( const std::wstring &  name)
explicit

Creates a new shared lock object by a system unique name of this lock.

Parameters
nameSystem wide unique lock name

◆ SharedLock() [3/3]

Ocean::SharedLock::SharedLock ( const SharedLock sharedLock)
delete

Disabled copy constructor.

Parameters
sharedLockShared lock object to be copied

◆ ~SharedLock()

Ocean::SharedLock::~SharedLock ( )

Destructs a shared lock object.

Member Function Documentation

◆ createSemaphore()

bool Ocean::SharedLock::createSemaphore ( )
private

Creates the semaphore object of this lock.

Returns
True, if succeeded

◆ isValid()

bool Ocean::SharedLock::isValid ( ) const
inline

Returns whether this object is valid and can be used correctly.

Returns
True, if so

◆ lock()

void Ocean::SharedLock::lock ( )

Looks the mutex.

Beware: This object must have a valid name before locking!

See also
unlock(), tryLock(), name(), isValid().

◆ name()

const std::wstring & Ocean::SharedLock::name ( ) const
inline

Returns the system wide unique name of this lock.

Returns
Lock name

◆ operator bool()

Ocean::SharedLock::operator bool ( ) const
inlineexplicit

Returns whether this object is valid and can be used correctly.

Returns
True, if so

◆ operator=()

SharedLock& Ocean::SharedLock::operator= ( const SharedLock sharedLock)
delete

Disabled assign operator.

Parameters
sharedLockShared lock object to be assigned
Returns
Reference to this object

◆ tryLock()

bool Ocean::SharedLock::tryLock ( )

Tries to lock the mutex.

Beware: This object must have a valid name before locking!

Returns
True, if the mutex could be locked
See also
unlock(), lock(), name(), isValid().

◆ unlock()

void Ocean::SharedLock::unlock ( )

Unlocks the mutex.

Beware: This object must have a valid name before locking!

See also
lock(), name(), isVaid().

Field Documentation

◆ handle_

void* Ocean::SharedLock::handle_ = nullptr
private

Handle of the mutex.

◆ localCounter_

unsigned int Ocean::SharedLock::localCounter_ = 0u
private

Local lock counter.

◆ localLock_

Lock Ocean::SharedLock::localLock_
private

Local lock object.

◆ name_

std::wstring Ocean::SharedLock::name_
private

System wide unique name.


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