Tkrzw
Public Member Functions | List of all members
tkrzw::SpinWPSharedMutex Class Referencefinal

Spin lock shared mutex, with write-preferring policy. More...

#include <tkrzw_thread_util.h>

Public Member Functions

 SpinWPSharedMutex ()
 Constructor. More...
 
 SpinWPSharedMutex (const SpinWPSharedMutex &rhs)=delete
 Copy and assignment are disabled. More...
 
SpinWPSharedMutexoperator= (const SpinWPSharedMutex &rhs)=delete
 
void lock ()
 Gets exclusive ownership of the lock. More...
 
bool try_lock ()
 Tries to get exclusive ownership of the lock. More...
 
void unlock ()
 Releases exclusive ownership of the lock. More...
 
void lock_shared ()
 Gets shared ownership of the lock. More...
 
bool try_lock_shared ()
 Tries to get shared ownership of the lock. More...
 
void unlock_shared ()
 Releases shared ownership of the lock. More...
 
bool try_upgrade (bool wait=false)
 Tries to upgrade shared ownership to exclusive ownership. More...
 
void downgrade ()
 Downgrades exclusive ownership.to shared ownership. More...
 

Detailed Description

Spin lock shared mutex, with write-preferring policy.

Constructor & Destructor Documentation

◆ SpinWPSharedMutex() [1/2]

tkrzw::SpinWPSharedMutex::SpinWPSharedMutex ( )

Constructor.

◆ SpinWPSharedMutex() [2/2]

tkrzw::SpinWPSharedMutex::SpinWPSharedMutex ( const SpinWPSharedMutex rhs)
explicitdelete

Copy and assignment are disabled.

Member Function Documentation

◆ lock()

void tkrzw::SpinWPSharedMutex::lock ( )

Gets exclusive ownership of the lock.

Precondition: The thread doesn't have any ownership.

◆ try_lock()

bool tkrzw::SpinWPSharedMutex::try_lock ( )

Tries to get exclusive ownership of the lock.

Returns
True if successful or false on failure.

Precondition: The thread doesn't have any ownership.

◆ unlock()

void tkrzw::SpinWPSharedMutex::unlock ( )

Releases exclusive ownership of the lock.

Precondition: The thread has the exclusive ownership.

◆ lock_shared()

void tkrzw::SpinWPSharedMutex::lock_shared ( )

Gets shared ownership of the lock.

Precondition: The thread doesn't have any ownership.

◆ try_lock_shared()

bool tkrzw::SpinWPSharedMutex::try_lock_shared ( )

Tries to get shared ownership of the lock.

Returns
True if successful or false on failure.

Precondition: The thread doesn't have any ownership.

◆ unlock_shared()

void tkrzw::SpinWPSharedMutex::unlock_shared ( )

Releases shared ownership of the lock.

Precondition: The thread has the shared ownership.

◆ try_upgrade()

bool tkrzw::SpinWPSharedMutex::try_upgrade ( bool  wait = false)

Tries to upgrade shared ownership to exclusive ownership.

Parameters
waitIf true, waits while there's possibility to get exclusive ownership.
Returns
True if successful or false on failure.

Precondition: The thread has the shared ownership.

◆ downgrade()

void tkrzw::SpinWPSharedMutex::downgrade ( )

Downgrades exclusive ownership.to shared ownership.

Precondition: The thread has the exclusive ownership.