| 1 |
/***************************************************************************** |
| 2 |
|
| 3 |
Copyright (c) 2012, 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/sync0policy.ic |
| 29 |
Policy for mutexes. |
| 30 |
|
| 31 |
Created 2012-08-21 Sunny Bains. |
| 32 |
***********************************************************************/ |
| 33 |
|
| 34 |
#include "sync0debug.h" |
| 35 |
|
| 36 |
template <typename Mutex> |
| 37 |
std::string GenericPolicy<Mutex>::to_string() const { |
| 38 |
return (sync_mutex_to_string(get_id(), sync_file_created_get(this))); |
| 39 |
} |
| 40 |
|
| 41 |
template <typename Mutex> |
| 42 |
std::string BlockMutexPolicy<Mutex>::to_string() const { |
| 43 |
/* I don't think it makes sense to keep track of the file name |
| 44 |
and line number for each block mutex. Too much of overhead. Use the |
| 45 |
latch id to figure out the location from the source. */ |
| 46 |
return (sync_mutex_to_string(get_id(), "buf0buf.cc:0")); |
| 47 |
} |
| 48 |
|
| 49 |
#ifdef UNIV_DEBUG |
| 50 |
|
| 51 |
template <typename Mutex> |
| 52 |
void MutexDebug<Mutex>::init(latch_id_t id) UNIV_NOTHROW { |
| 53 |
m_context.m_id = id; |
| 54 |
|
| 55 |
m_context.release(); |
| 56 |
|
| 57 |
m_magic_n = MUTEX_MAGIC_N; |
| 58 |
} |
| 59 |
|
| 60 |
template <typename Mutex> |
| 61 |
void MutexDebug<Mutex>::enter(const Mutex *mutex, const char *name, |
| 62 |
ulint line) UNIV_NOTHROW { |
| 63 |
ut_ad(!is_owned()); |
| 64 |
ut_ad(m_magic_n == MUTEX_MAGIC_N); |
| 65 |
|
| 66 |
Context context(m_context.get_id()); |
| 67 |
|
| 68 |
context.locked(mutex, name, line); |
| 69 |
|
| 70 |
/* Check for latch order violation. */ |
| 71 |
|
| 72 |
sync_check_lock_validate(&context); |
| 73 |
} |
| 74 |
|
| 75 |
template <typename Mutex> |
| 76 |
void MutexDebug<Mutex>::locked(const Mutex *mutex, const char *name, |
| 77 |
ulint line) UNIV_NOTHROW { |
| 78 |
ut_ad(!is_owned()); |
| 79 |
ut_ad(m_context.m_thread_id == std::thread::id{}); |
| 80 |
|
| 81 |
m_context.locked(mutex, name, line); |
| 82 |
|
| 83 |
sync_check_lock_granted(&m_context); |
| 84 |
} |
| 85 |
|
| 86 |
template <typename Mutex> |
| 87 |
void MutexDebug<Mutex>::release(const Mutex *) UNIV_NOTHROW { |
| 88 |
ut_ad(is_owned()); |
| 89 |
|
| 90 |
m_context.release(); |
| 91 |
|
| 92 |
sync_check_unlock(&m_context); |
| 93 |
} |
| 94 |
|
| 95 |
#endif /* UNIV_DEBUG */ |