1/*****************************************************************************
2
3Copyright (c) 2013, 2015, Oracle and/or its affiliates. All Rights Reserved.
4Copyright (c) 2017, MariaDB Corporation.
5
6Portions of this file contain modifications contributed and copyrighted by
7Google, Inc. Those modifications are gratefully acknowledged and are described
8briefly in the InnoDB documentation. The contributions by Google are
9incorporated with their permission, and subject to the conditions contained in
10the file COPYING.Google.
11
12This program is free software; you can redistribute it and/or modify it under
13the terms of the GNU General Public License as published by the Free Software
14Foundation; version 2 of the License.
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 for more details.
19
20You should have received a copy of the GNU General Public License along with
21this program; if not, write to the Free Software Foundation, Inc.,
2251 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
23
24*****************************************************************************/
25
26/**************************************************//**
27@file include/sync0debug.h
28Debug checks for latches, header file
29
30Created 2012-08-21 Sunny Bains
31*******************************************************/
32
33#ifndef sync0debug_h
34#define sync0debug_h
35
36#include "univ.i"
37#include "sync0types.h"
38
39/** Initializes the synchronization data structures. */
40void
41sync_check_init();
42
43/** Free the InnoDB synchronization data structures. */
44void
45sync_check_close();
46
47#ifdef UNIV_DEBUG
48/** Enable sync order checking. */
49void
50sync_check_enable();
51
52/** Check if it is OK to acquire the latch.
53@param[in] latch latch type */
54void
55sync_check_lock_validate(const latch_t* latch);
56
57/** Note that the lock has been granted
58@param[in] latch latch type */
59void
60sync_check_lock_granted(const latch_t* latch);
61
62/** Check if it is OK to acquire the latch.
63@param[in] latch latch type
64@param[in] level the level of the mutex */
65void
66sync_check_lock(const latch_t* latch, latch_level_t level);
67
68/**
69Check if it is OK to re-acquire the lock. */
70void
71sync_check_relock(const latch_t* latch);
72
73/** Removes a latch from the thread level array if it is found there.
74@param[in] latch to unlock */
75void
76sync_check_unlock(const latch_t* latch);
77
78/** Checks if the level array for the current thread contains a
79mutex or rw-latch at the specified level.
80@param[in] level to find
81@return a matching latch, or NULL if not found */
82const latch_t*
83sync_check_find(latch_level_t level);
84
85/** Checks that the level array for the current thread is empty.
86Terminate iteration if the functor returns true.
87@param[in] functor called for each element.
88@return true if the functor returns true for any element */
89bool
90sync_check_iterate(const sync_check_functor_t& functor);
91
92/** Acquires the debug mutex. We cannot use the mutex defined in sync0sync,
93because the debug mutex is also acquired in sync0arr while holding the OS
94mutex protecting the sync array, and the ordinary mutex_enter might
95recursively call routines in sync0arr, leading to a deadlock on the OS
96mutex. */
97void
98rw_lock_debug_mutex_enter();
99
100/** Releases the debug mutex. */
101void
102rw_lock_debug_mutex_exit();
103
104#endif /* UNIV_DEBUG */
105
106#endif /* !sync0debug_h */
107