MySQL 9.0.0
Source Code Documentation
Checkable_rwlock Class Reference

This has the functionality of mysql_rwlock_t, with two differences: More...

#include <rpl_gtid.h>

Classes

class  Guard
 RAII class to acquire a lock for the duration of a block. More...
 

Public Types

enum  enum_lock_type {
  NO_LOCK , READ_LOCK , WRITE_LOCK , TRY_READ_LOCK ,
  TRY_WRITE_LOCK
}
 

Public Member Functions

 Checkable_rwlock (PSI_rwlock_key psi_key=0)
 Initialize this Checkable_rwlock. More...
 
 ~Checkable_rwlock ()
 Destroy this Checkable_lock. More...
 
void rdlock ()
 Acquire the read lock. More...
 
void wrlock ()
 Acquire the write lock. More...
 
void unlock ()
 Release the lock (whether it is a write or read lock). More...
 
bool is_wrlock ()
 Return true if the write lock is held. More...
 
int trywrlock ()
 Return 0 if the write lock is held, otherwise an error will be returned. More...
 
int tryrdlock ()
 Return 0 if the read lock is held, otherwise an error will be returned. More...
 
void assert_some_lock () const
 Assert that some thread holds either the read or the write lock. More...
 
void assert_some_rdlock () const
 Assert that some thread holds the read lock. More...
 
void assert_some_wrlock () const
 Assert that some thread holds the write lock. More...
 
void assert_no_wrlock () const
 Assert that no thread holds the write lock. More...
 
void assert_no_rdlock () const
 Assert that no thread holds the read lock. More...
 
void assert_no_lock () const
 Assert that no thread holds read or write lock. More...
 

Public Attributes

bool m_dbug_trace
 If enabled, print any lock/unlock operations to the DBUG trace. More...
 

Private Member Functions

int32 get_state () const
 Read lock_state atomically and return the value. More...
 

Private Attributes

std::atomic< int32m_lock_state
 The state of the lock: 0 - not locked -1 - write locked >0 - read locked by that many threads. More...
 
mysql_rwlock_t m_rwlock {}
 The rwlock. More...
 

Detailed Description

This has the functionality of mysql_rwlock_t, with two differences:

  1. It has additional operations to check if the read and/or write lock is held at the moment.
  2. It is wrapped in an object-oriented interface.

Note that the assertions do not check whether this thread has taken the lock (that would be more complicated as it would require a dynamic data structure). Luckily, it is still likely that the assertions find bugs where a thread forgot to take a lock, because most of the time most locks are only used by one thread at a time.

The assertions are no-ops when DBUG is off.

Member Enumeration Documentation

◆ enum_lock_type

Enumerator
NO_LOCK 
READ_LOCK 
WRITE_LOCK 
TRY_READ_LOCK 
TRY_WRITE_LOCK 

Constructor & Destructor Documentation

◆ Checkable_rwlock()

Checkable_rwlock::Checkable_rwlock ( PSI_rwlock_key  psi_key = 0)
inline

Initialize this Checkable_rwlock.

◆ ~Checkable_rwlock()

Checkable_rwlock::~Checkable_rwlock ( )
inline

Destroy this Checkable_lock.

Member Function Documentation

◆ assert_no_lock()

void Checkable_rwlock::assert_no_lock ( ) const
inline

Assert that no thread holds read or write lock.

◆ assert_no_rdlock()

void Checkable_rwlock::assert_no_rdlock ( ) const
inline

Assert that no thread holds the read lock.

◆ assert_no_wrlock()

void Checkable_rwlock::assert_no_wrlock ( ) const
inline

Assert that no thread holds the write lock.

◆ assert_some_lock()

void Checkable_rwlock::assert_some_lock ( ) const
inline

Assert that some thread holds either the read or the write lock.

◆ assert_some_rdlock()

void Checkable_rwlock::assert_some_rdlock ( ) const
inline

Assert that some thread holds the read lock.

◆ assert_some_wrlock()

void Checkable_rwlock::assert_some_wrlock ( ) const
inline

Assert that some thread holds the write lock.

◆ get_state()

int32 Checkable_rwlock::get_state ( ) const
inlineprivate

Read lock_state atomically and return the value.

◆ is_wrlock()

bool Checkable_rwlock::is_wrlock ( )
inline

Return true if the write lock is held.

Must only be called by threads that hold a lock.

◆ rdlock()

void Checkable_rwlock::rdlock ( )
inline

Acquire the read lock.

◆ tryrdlock()

int Checkable_rwlock::tryrdlock ( )
inline

Return 0 if the read lock is held, otherwise an error will be returned.

◆ trywrlock()

int Checkable_rwlock::trywrlock ( )
inline

Return 0 if the write lock is held, otherwise an error will be returned.

◆ unlock()

void Checkable_rwlock::unlock ( )
inline

Release the lock (whether it is a write or read lock).

◆ wrlock()

void Checkable_rwlock::wrlock ( )
inline

Acquire the write lock.

Member Data Documentation

◆ m_dbug_trace

bool Checkable_rwlock::m_dbug_trace

If enabled, print any lock/unlock operations to the DBUG trace.

◆ m_lock_state

std::atomic<int32> Checkable_rwlock::m_lock_state
private

The state of the lock: 0 - not locked -1 - write locked >0 - read locked by that many threads.

◆ m_rwlock

mysql_rwlock_t Checkable_rwlock::m_rwlock {}
private

The rwlock.


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