MySQL 9.1.0
Source Code Documentation
Mutex_cond_array Class Reference

Represents a growable array where each element contains a mutex and a condition variable. More...

#include <rpl_gtid.h>

Classes

struct  Mutex_cond
 A mutex/cond pair. More...
 

Public Member Functions

 Mutex_cond_array (Checkable_rwlock *global_lock)
 Create a new Mutex_cond_array. More...
 
 ~Mutex_cond_array ()
 Destroy this object. More...
 
void lock (int n) const
 Lock the n'th mutex. More...
 
void unlock (int n) const
 Unlock the n'th mutex. More...
 
void broadcast (int n) const
 Broadcast the n'th condition. More...
 
void assert_owner (int n) const
 Assert that this thread owns the n'th mutex. More...
 
void assert_not_owner (int n) const
 Assert that this thread does not own the n'th mutex. More...
 
bool wait (const THD *thd, int sidno, struct timespec *abstime) const
 Wait for signal on the n'th condition variable. More...
 
void enter_cond (THD *thd, int n, PSI_stage_info *stage, PSI_stage_info *old_stage) const
 Execute THD::enter_cond for the n'th condition variable. More...
 
int get_max_index () const
 Return the greatest addressable index in this Mutex_cond_array. More...
 
enum_return_status ensure_index (int n)
 Grows the array so that the given index fits. More...
 

Private Member Functions

bool is_thd_killed (const THD *thd) const
 Return true if the given THD is killed. More...
 
Mutex_condget_mutex_cond (int n) const
 Return the Nth Mutex_cond object. More...
 

Private Attributes

Checkable_rwlockglobal_lock
 Read-write lock that protects updates to the number of elements. More...
 
Prealloced_array< Mutex_cond *, 8 > m_array
 

Detailed Description

Represents a growable array where each element contains a mutex and a condition variable.

Each element can be locked, unlocked, broadcast, or waited for, and it is possible to call "THD::enter_cond" for the condition. The allowed indexes range from 0, inclusive, to get_max_index(), inclusive. Initially there are zero elements (and get_max_index() returns -1); more elements can be allocated by calling ensure_index().

This data structure has a read-write lock that protects the number of elements. The lock is provided by the invoker of the constructor and it is generally the caller's responsibility to acquire the read lock. Access methods assert that the caller already holds the read (or write) lock. If a method of this class grows the number of elements, then the method temporarily upgrades this lock to a write lock and then degrades it to a read lock again; there will be a short period when the lock is not held at all.

Constructor & Destructor Documentation

◆ Mutex_cond_array()

Mutex_cond_array::Mutex_cond_array ( Checkable_rwlock global_lock)

Create a new Mutex_cond_array.

Parameters
global_lockRead-write lock that protects updates to the number of elements.

◆ ~Mutex_cond_array()

Mutex_cond_array::~Mutex_cond_array ( )

Destroy this object.

Member Function Documentation

◆ assert_not_owner()

void Mutex_cond_array::assert_not_owner ( int  n) const
inline

Assert that this thread does not own the n'th mutex.

This is a no-op if NDEBUG is on.

◆ assert_owner()

void Mutex_cond_array::assert_owner ( int  n) const
inline

Assert that this thread owns the n'th mutex.

This is a no-op if NDEBUG is on.

◆ broadcast()

void Mutex_cond_array::broadcast ( int  n) const
inline

Broadcast the n'th condition.

◆ ensure_index()

enum_return_status Mutex_cond_array::ensure_index ( int  n)

Grows the array so that the given index fits.

If the array is grown, the global_lock is temporarily upgraded to a write lock and then degraded again; there will be a short period when the lock is not held at all.

Parameters
nThe index.
Returns
RETURN_OK or RETURN_REPORTED_ERROR

◆ enter_cond()

void Mutex_cond_array::enter_cond ( THD thd,
int  n,
PSI_stage_info stage,
PSI_stage_info old_stage 
) const

Execute THD::enter_cond for the n'th condition variable.

◆ get_max_index()

int Mutex_cond_array::get_max_index ( ) const
inline

Return the greatest addressable index in this Mutex_cond_array.

◆ get_mutex_cond()

Mutex_cond * Mutex_cond_array::get_mutex_cond ( int  n) const
inlineprivate

Return the Nth Mutex_cond object.

◆ is_thd_killed()

bool Mutex_cond_array::is_thd_killed ( const THD thd) const
private

Return true if the given THD is killed.

Parameters
[in]thd- The thread object
Return values
true- thread is killed false - thread not killed

◆ lock()

void Mutex_cond_array::lock ( int  n) const
inline

Lock the n'th mutex.

◆ unlock()

void Mutex_cond_array::unlock ( int  n) const
inline

Unlock the n'th mutex.

◆ wait()

bool Mutex_cond_array::wait ( const THD thd,
int  sidno,
struct timespec *  abstime 
) const
inline

Wait for signal on the n'th condition variable.

The caller must hold the read lock or write lock on tsid_lock, as well as the nth mutex lock, before invoking this function. The tsid_lock will be released, whereas the mutex will be released during the wait and (atomically) re-acquired when the wait ends or the timeout is reached.

Parameters
[in]thdTHD object for the calling thread.
[in]sidnoCondition variable to wait for.
[in]abstimeThe absolute point in time when the wait times out and stops, or NULL to wait indefinitely.
Return values
falseSuccess.
trueFailure: either timeout or thread was killed. If thread was killed, the error has been generated.

Member Data Documentation

◆ global_lock

Checkable_rwlock* Mutex_cond_array::global_lock
mutableprivate

Read-write lock that protects updates to the number of elements.

◆ m_array

Prealloced_array<Mutex_cond *, 8> Mutex_cond_array::m_array
private

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