MySQL 9.1.0
Source Code Documentation
|
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_cond * | get_mutex_cond (int n) const |
Return the Nth Mutex_cond object. More... | |
Private Attributes | |
Checkable_rwlock * | global_lock |
Read-write lock that protects updates to the number of elements. More... | |
Prealloced_array< Mutex_cond *, 8 > | m_array |
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.
Mutex_cond_array::Mutex_cond_array | ( | Checkable_rwlock * | global_lock | ) |
Create a new Mutex_cond_array.
global_lock | Read-write lock that protects updates to the number of elements. |
Mutex_cond_array::~Mutex_cond_array | ( | ) |
Destroy this object.
|
inline |
Assert that this thread does not own the n'th mutex.
This is a no-op if NDEBUG is on.
|
inline |
Assert that this thread owns the n'th mutex.
This is a no-op if NDEBUG is on.
|
inline |
Broadcast the n'th condition.
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.
n | The index. |
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.
|
inline |
Return the greatest addressable index in this Mutex_cond_array.
|
inlineprivate |
Return the Nth Mutex_cond object.
|
private |
Return true if the given THD is killed.
[in] | thd | - The thread object |
true | - thread is killed false - thread not killed |
|
inline |
Lock the n'th mutex.
|
inline |
Unlock the n'th mutex.
|
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.
[in] | thd | THD object for the calling thread. |
[in] | sidno | Condition variable to wait for. |
[in] | abstime | The absolute point in time when the wait times out and stops, or NULL to wait indefinitely. |
false | Success. |
true | Failure: either timeout or thread was killed. If thread was killed, the error has been generated. |
|
mutableprivate |
Read-write lock that protects updates to the number of elements.
|
private |