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