MySQL 9.1.0
Source Code Documentation
|
The wait array used in synchronization primitives. More...
#include "sync0arr.h"
#include <sys/types.h>
#include <time.h>
#include "lock0lock.h"
#include "os0event.h"
#include "os0file.h"
#include "srv0srv.h"
#include "sync0arr_impl.h"
#include "sync0debug.h"
#include "sync0sync.h"
Macros | |
#define | sync_array_exit(a) mutex_exit(&(a)->mutex) |
#define | sync_array_enter(a) mutex_enter(&(a)->mutex) |
Functions | |
static bool | sync_array_detect_deadlock (sync_array_t *arr, sync_cell_t *cell, size_t depth) |
Detects a deadlock of one or more threads because of waits of semaphores. More... | |
static void | sync_array_validate (sync_array_t *arr) |
Validates the integrity of the wait array. More... | |
sync_cell_t * | sync_array_get_nth_cell (sync_array_t *arr, ulint n) |
Gets the nth cell in array. More... | |
static void | sync_array_free (sync_array_t *arr) |
Frees the resources in a wait array. More... | |
static os_event_t | sync_cell_get_event (sync_cell_t *cell) |
Returns the event that the thread owning the cell waits for. More... | |
sync_cell_t * | sync_array_reserve_cell (sync_array_t *arr, void *object, ulint type, ut::Location location) |
Reserves a wait array cell for waiting for an object. More... | |
void | sync_array_free_cell (sync_array_t *arr, sync_cell_t *&cell) |
Frees the cell. More... | |
void | sync_array_detect_deadlock () |
void | sync_array_wait_event (sync_array_t *arr, sync_cell_t *&cell) |
This function should be called when a thread starts to wait on a wait array cell. More... | |
template<typename Mutex > | |
static void | sync_array_mutex_print (FILE *file, const Mutex *mutex) |
Reports info about a mutex (seen locked a moment ago) into a file. More... | |
void | sync_array_cell_print (FILE *file, const sync_cell_t *cell) |
Reports info of a wait array cell into a file. More... | |
static sync_cell_t * | sync_array_find_thread (sync_array_t *arr, std::thread::id thread) |
Looks for a cell with the given thread id. More... | |
static bool | sync_array_deadlock_step (sync_array_t *arr, std::thread::id thread, size_t depth) |
Recursion step for deadlock detection. More... | |
template<typename Mutex > | |
static bool | sync_array_detect_mutex_deadlock (const Mutex *mutex, sync_array_t *arr, sync_cell_t *cell, size_t depth) |
A helper for sync_array_detect_deadlock() to handle the case when the cell contains a thread waiting for a mutex. More... | |
template<typename F > | |
bool | sync_array_detect_rwlock_deadlock (sync_cell_t *cell, sync_array_t *arr, const size_t depth, F &&conflicts) |
static bool | sync_array_detect_deadlock_low (sync_array_t *arr, sync_cell_t *cell, size_t depth) |
static bool | sync_arr_cell_can_wake_up (sync_cell_t *cell) |
Determines if we can wake up the thread waiting for a semaphore. More... | |
void | sync_array_object_signalled () |
Increments the signalled count. More... | |
static void | sync_array_wake_threads_if_sema_free_low (sync_array_t *arr) |
If the wakeup algorithm does not work perfectly at semaphore releases, this function will do the waking (see the comment in mutex_exit). More... | |
void | sync_arr_wake_threads_if_sema_free (void) |
If the wakeup algorithm does not work perfectly at semaphore releases, this function will do the waking (see the comment in mutex_exit). More... | |
static bool | sync_array_print_long_waits_low (sync_array_t *arr, std::thread::id *waiter, const void **sema, bool *noticed) |
Prints warnings of long semaphore waits to stderr. More... | |
bool | sync_array_print_long_waits (std::thread::id *waiter, const void **sema) |
Prints warnings of long semaphore waits to stderr. More... | |
static void | sync_array_print_info_low (FILE *file, sync_array_t *arr) |
Prints info of the wait array. More... | |
static void | sync_array_print_info (FILE *file, sync_array_t *arr) |
Prints info of the wait array. More... | |
void | sync_array_init (ulint n_threads) |
Create the primary system wait array(s), they are protected by an OS mutex. More... | |
void | sync_array_close (void) |
Close sync array wait sub-system. More... | |
void | sync_array_print (FILE *file) |
Print info about the sync array(s). More... | |
Variables | |
ulong | srv_sync_array_size = 1 |
User configured sync array size. More... | |
ulint | sync_array_size |
Locally stored copy of srv_sync_array_size. More... | |
sync_array_t ** | sync_wait_array |
The global array of wait cells for implementation of the database's own mutexes and read-write locks. More... | |
static ulint | sg_count |
count of how many times an object has been signalled More... | |
The wait array used in synchronization primitives.
Created 9/5/1995 Heikki Tuuri
#define sync_array_enter | ( | a | ) | mutex_enter(&(a)->mutex) |
#define sync_array_exit | ( | a | ) | mutex_exit(&(a)->mutex) |
|
static |
Determines if we can wake up the thread waiting for a semaphore.
cell | in: cell to search |
void sync_arr_wake_threads_if_sema_free | ( | void | ) |
If the wakeup algorithm does not work perfectly at semaphore releases, this function will do the waking (see the comment in mutex_exit).
This function should be called about every 1 second in the server.
Note that there's a race condition between this thread and mutex_exit changing the lock_word and calling signal_object, so sometimes this finds threads to wake up even when nothing has gone wrong.
void sync_array_cell_print | ( | FILE * | file, |
const sync_cell_t * | cell | ||
) |
Reports info of a wait array cell into a file.
[in] | file | File where to print. |
[in] | cell | Sync array cell to report. |
void sync_array_close | ( | void | ) |
Close sync array wait sub-system.
|
static |
Recursion step for deadlock detection.
[in] | arr | The wait array we limit our search for cycle to. The caller must own the arr->mutex. |
[in] | thread | The thread which blocking other threads, which we want to find in the arr, to know if and why it's blocked, too |
[in] | depth | The recursion depth |
void sync_array_detect_deadlock | ( | ) |
|
static |
Detects a deadlock of one or more threads because of waits of semaphores.
Reports a fatal error (and thus does not return) in case it finds one. The return value is only used in recursive calls (depth>0).
[in] | arr | The wait array we limit our search for cycle to. The caller must own the arr->mutex. |
[in] | cell | The cell to check |
[in] | depth | The recursion depth |
|
static |
|
static |
A helper for sync_array_detect_deadlock() to handle the case when the cell contains a thread waiting for a mutex.
[in] | mutex | the mutex to check |
[in] | arr | wait array; NOTE! the caller must own the mutex to array |
[in] | cell | the cell which contains the mutex |
[in] | depth | recursion depth |
bool sync_array_detect_rwlock_deadlock | ( | sync_cell_t * | cell, |
sync_array_t * | arr, | ||
const size_t | depth, | ||
F && | conflicts | ||
) |
|
static |
Looks for a cell with the given thread id.
arr | in: wait array |
thread | in: thread id |
|
static |
Frees the resources in a wait array.
arr | in, own: sync wait array |
void sync_array_free_cell | ( | sync_array_t * | arr, |
sync_cell_t *& | cell | ||
) |
Frees the cell.
NOTE! sync_array_wait_event frees the cell automatically!
arr | in: wait array |
cell | in/out: the cell in the array |
sync_cell_t * sync_array_get_nth_cell | ( | sync_array_t * | arr, |
ulint | n | ||
) |
Gets the nth cell in array.
[in] | arr | Sync array to get cell from. |
[in] | n | Index of cell to retrieve. |
void sync_array_init | ( | ulint | n_threads | ) |
Create the primary system wait array(s), they are protected by an OS mutex.
in: Number of slots to create
n_threads | in: Number of slots to create in all arrays |
|
static |
Reports info about a mutex (seen locked a moment ago) into a file.
[in] | file | File where to print. |
[in] | mutex | The mutex to describe. |
void sync_array_object_signalled | ( | ) |
Increments the signalled count.
Note that one of the wait objects was signalled.
void sync_array_print | ( | FILE * | file | ) |
Print info about the sync array(s).
Prints info of the wait array.
file | in/out: Print to this stream |
|
static |
Prints info of the wait array.
file | in: file where to print |
arr | in: wait array |
|
static |
Prints info of the wait array.
file | in: file where to print |
arr | in: wait array |
bool sync_array_print_long_waits | ( | std::thread::id * | waiter, |
const void ** | sema | ||
) |
Prints warnings of long semaphore waits to stderr.
waiter | out: longest waiting thread |
sema | out: longest-waited-for semaphore |
|
static |
Prints warnings of long semaphore waits to stderr.
arr | in: sync array instance |
waiter | out: longest waiting thread |
sema | out: longest-waited-for semaphore |
noticed | out: true if long wait noticed |
sync_cell_t * sync_array_reserve_cell | ( | sync_array_t * | arr, |
void * | object, | ||
ulint | type, | ||
ut::Location | location | ||
) |
Reserves a wait array cell for waiting for an object.
The event of the cell is reset to nonsignalled state.
[in] | arr | wait array |
[in] | object | pointer to the object to wait for |
[in] | type | lock request type |
[in] | location | location where requested |
|
static |
Validates the integrity of the wait array.
Checks that the number of reserved cells equals the count variable.
arr | in: sync wait array |
void sync_array_wait_event | ( | sync_array_t * | arr, |
sync_cell_t *& | cell | ||
) |
This function should be called when a thread starts to wait on a wait array cell.
In the debug version this function checks if the wait for a semaphore will result in a deadlock, in which case prints info and asserts.
arr | in: wait array |
cell | in: index of the reserved cell |
|
static |
If the wakeup algorithm does not work perfectly at semaphore releases, this function will do the waking (see the comment in mutex_exit).
This function should be called about every 1 second in the server.
Note that there's a race condition between this thread and mutex_exit changing the lock_word and calling signal_object, so sometimes this finds threads to wake up even when nothing has gone wrong.
|
static |
Returns the event that the thread owning the cell waits for.
cell | in: non-empty sync array cell |
|
static |
count of how many times an object has been signalled
ulong srv_sync_array_size = 1 |
User configured sync array size.
ulint sync_array_size |
Locally stored copy of srv_sync_array_size.
sync_array_t** sync_wait_array |
The global array of wait cells for implementation of the database's own mutexes and read-write locks.