My Project
Classes | Public Member Functions
Mutex_cond_array Class Reference

#include <rpl_gtid.h>

List of all members.


struct  Mutex_cond
 A mutex/cond pair.

Public Member Functions

 Mutex_cond_array (Checkable_rwlock *global_lock)
 ~Mutex_cond_array ()
 Destroy this object.
void lock (int n) const
 Lock the n'th mutex.
void unlock (int n) const
 Unlock the n'th mutex.
void broadcast (int n) const
 Broadcast the n'th condition.
void assert_owner (int n) const
void assert_not_owner (int n) const
void wait (int n) const
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.
int get_max_index () const
 Return the greatest addressable index in this Mutex_cond_array.
enum_return_status ensure_index (int n)

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

Create a new Mutex_cond_array.

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

Member Function Documentation

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 DBUG_OFF is on.

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 DBUG_OFF is on.

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.

nThe index.
void Mutex_cond_array::wait ( int  n) const [inline]

Wait for signal on the n'th condition variable.

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

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines