Debian Codegraph @

storage/innobase/include/sync0arr.h

raw
1 /*****************************************************************************
2
3 Copyright (c) 1995, 2026, Oracle and/or its affiliates.
4
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License, version 2.0, as published by the
7 Free Software Foundation.
8
9 This program is designed to work with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation. The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have either included with
15 the program or referenced in the documentation.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20 for more details.
21
22 You should have received a copy of the GNU General Public License along with
23 this program; if not, write to the Free Software Foundation, Inc.,
24 51 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 */
40 struct sync_cell_t;
41
42 /** Synchronization wait array */
43 struct sync_array_t;
44
45 /** Get an instance of the sync wait array and reserve a wait array cell in
46 the instance for waiting for an object. The event of the cell is reset to
47 nonsignalled state.
48 If reserving cell of the instance fails, try to get another new instance until
49 we 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. */
55 static inline sync_array_t *sync_array_get_and_reserve_cell(
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*/
65 sync_cell_t *sync_array_reserve_cell(sync_array_t *arr, void *object,
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. */
72 void 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! */
77 void 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. */
81 void sync_array_object_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. */
86 void sync_arr_wake_threads_if_sema_free();
87
88 /** Prints warnings of long semaphore waits to stderr.
89 @return true if fatal semaphore wait threshold was exceeded */
90 bool sync_array_print_long_waits(
91 std::thread::id *waiter, /*!< out: longest waiting thread */
92 const void **sema); /*!< out: longest-waited-for semaphore */
93
94 void sync_array_detect_deadlock();
95
96 /** Prints info of the wait array. */
97 void 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 */
101 void sync_array_init(ulint n_threads); /*!< in: Number of slots to create */
102
103 /** Close sync array wait sub-system. */
104 void sync_array_close();
105
106 /** Get an instance of the sync wait array. */
107 static inline sync_array_t *sync_array_get();
108
109 #include "sync0arr.ic"
110
111 #endif /* sync0arr_h */