MySQL 8.0.31
Source Code Documentation
sync0arr.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1995, 2022, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is also distributed with certain software (including but not
10limited to OpenSSL) that is licensed under separate terms, as designated in a
11particular file or component or in included license documentation. The authors
12of MySQL hereby grant you an additional permission to link the program and
13your derivative works with the separately licensed software that they have
14included with MySQL.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19for more details.
20
21You should have received a copy of the GNU General Public License along with
22this program; if not, write to the Free Software Foundation, Inc.,
2351 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
25*****************************************************************************/
26
27/** @file include/sync0arr.h
28 The wait array used in synchronization primitives
29
30 Created 9/5/1995 Heikki Tuuri
31 *******************************************************/
32
33#ifndef sync0arr_h
34#define sync0arr_h
35
36#include "univ.i"
37
38/** Synchronization wait array cell */
39struct sync_cell_t;
40
41/** Synchronization wait array */
42struct sync_array_t;
43
44/** Get an instance of the sync wait array and reserve a wait array cell in
45the instance for waiting for an object. The event of the cell is reset to
46nonsignalled state.
47If reserving cell of the instance fails, try to get another new instance until
48we can reserve an empty cell of it.
49@param[in] object pointer to the object to wait for
50@param[in] type lock request type
51@param[in] location location where requested
52@param[out] cell the cell reserved, never NULL
53@return the sync array found, never NULL. */
55 void *object, ulint type, ut::Location location, sync_cell_t **cell);
56
57/** Reserves a wait array cell for waiting for an object.
58 The event of the cell is reset to nonsignalled state.
59 @param[in] arr wait array
60 @param[in] object pointer to the object to wait for
61 @param[in] type lock request type
62 @param[in] location location where requested
63 @return sync cell to wait on*/
65 ulint type, ut::Location location);
66
67/** This function should be called when a thread starts to wait on
68 a wait array cell. In the debug version this function checks
69 if the wait for a semaphore will result in a deadlock, in which
70 case prints info and asserts. */
71void sync_array_wait_event(sync_array_t *arr, /*!< in: wait array */
72 sync_cell_t *&cell); /*!< in: the reserved cell */
73
74/** Frees the cell. NOTE! sync_array_wait_event frees the cell
75 automatically! */
76void sync_array_free_cell(sync_array_t *arr, /*!< in: wait array */
77 sync_cell_t *&cell); /*!< in: the reserved cell */
78
79/** Note that one of the wait objects was signalled. */
81
82/** If the wakeup algorithm does not work perfectly at semaphore releases,
83 this function will do the waking (see the comment in mutex_exit). This
84 function should be called about every 1 second in the server. */
86
87/** Prints warnings of long semaphore waits to stderr.
88 @return true if fatal semaphore wait threshold was exceeded */
90 std::thread::id *waiter, /*!< out: longest waiting thread */
91 const void **sema); /*!< out: longest-waited-for semaphore */
92
94
95/** Prints info of the wait array. */
96void sync_array_print(FILE *file); /*!< in: file where to print */
97
98/** Create the primary system wait array(s), they are protected by an OS mutex
99 */
100void sync_array_init(ulint n_threads); /*!< in: Number of slots to create */
101
102/** Close sync array wait sub-system. */
103void sync_array_close();
104
105/** Get an instance of the sync wait array. */
107
108#include "sync0arr.ic"
109
110#endif /* sync0arr_h */
const std::string FILE("FILE")
Definition: os0file.h:85
required string type
Definition: replication_group_member_actions.proto:33
Synchronization array.
Definition: sync0arr_impl.h:122
A cell where an individual thread may wait suspended until a resource is released.
Definition: sync0arr_impl.h:82
Definition: ut0core.h:32
void sync_array_init(ulint n_threads)
Create the primary system wait array(s), they are protected by an OS mutex.
Definition: sync0arr.cc:940
static sync_array_t * sync_array_get_and_reserve_cell(void *object, ulint type, ut::Location location, sync_cell_t **cell)
Get an instance of the sync wait array and reserve a wait array cell in the instance for waiting for ...
void sync_array_detect_deadlock()
Definition: sync0arr.cc:280
void sync_array_object_signalled()
Note that one of the wait objects was signalled.
Definition: sync0arr.cc:737
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.
Definition: sync0arr.cc:310
void sync_array_print(FILE *file)
Prints info of the wait array.
Definition: sync0arr.cc:971
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.
Definition: sync0arr.cc:179
void sync_array_close()
Close sync array wait sub-system.
Definition: sync0arr.cc:961
static sync_array_t * sync_array_get()
Get an instance of the sync wait array.
void sync_array_free_cell(sync_array_t *arr, sync_cell_t *&cell)
Frees the cell.
Definition: sync0arr.cc:243
bool sync_array_print_long_waits(std::thread::id *waiter, const void **sema)
Prints warnings of long semaphore waits to stderr.
Definition: sync0arr.cc:853
void sync_arr_wake_threads_if_sema_free()
If the wakeup algorithm does not work perfectly at semaphore releases, this function will do the waki...
Definition: sync0arr.cc:775
The wait array for synchronization primitives.
Version control for database, common definitions, and include files.
unsigned long int ulint
Definition: univ.i:407
unsigned long id[MAX_DEAD]
Definition: xcom_base.cc:506