| 1 | /***************************************************************************** |
| 2 | |
| 3 | Copyright (c) 2013, 2015, Oracle and/or its affiliates. All Rights Reserved. |
| 4 | Copyright (c) 2017, MariaDB Corporation. |
| 5 | |
| 6 | This program is free software; you can redistribute it and/or modify it under |
| 7 | the terms of the GNU General Public License as published by the Free Software |
| 8 | Foundation; version 2 of the License. |
| 9 | |
| 10 | This program is distributed in the hope that it will be useful, but WITHOUT |
| 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 12 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU General Public License along with |
| 15 | this program; if not, write to the Free Software Foundation, Inc., |
| 16 | 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA |
| 17 | |
| 18 | *****************************************************************************/ |
| 19 | |
| 20 | /******************************************************************//** |
| 21 | @file include/sync0policy.ic |
| 22 | Policy for mutexes. |
| 23 | |
| 24 | Created 2012-08-21 Sunny Bains. |
| 25 | ***********************************************************************/ |
| 26 | |
| 27 | #include "sync0debug.h" |
| 28 | |
| 29 | template <typename Mutex> |
| 30 | std::string GenericPolicy<Mutex>::to_string() const |
| 31 | { |
| 32 | return(sync_mutex_to_string(get_id(), sync_file_created_get(this))); |
| 33 | } |
| 34 | |
| 35 | template <typename Mutex> |
| 36 | std::string BlockMutexPolicy<Mutex>::to_string() const |
| 37 | { |
| 38 | /* I don't think it makes sense to keep track of the file name |
| 39 | and line number for each block mutex. Too much of overhead. Use the |
| 40 | latch id to figure out the location from the source. */ |
| 41 | return(sync_mutex_to_string(get_id(), "buf0buf.cc:0" )); |
| 42 | } |
| 43 | |
| 44 | #ifdef UNIV_DEBUG |
| 45 | |
| 46 | template <typename Mutex> |
| 47 | void MutexDebug<Mutex>::init(latch_id_t id) |
| 48 | UNIV_NOTHROW |
| 49 | { |
| 50 | m_context.m_id = id; |
| 51 | |
| 52 | m_context.release(); |
| 53 | |
| 54 | m_magic_n = MUTEX_MAGIC_N; |
| 55 | } |
| 56 | |
| 57 | template <typename Mutex> |
| 58 | void MutexDebug<Mutex>::enter( |
| 59 | const Mutex* mutex, |
| 60 | const char* name, |
| 61 | unsigned line) |
| 62 | UNIV_NOTHROW |
| 63 | { |
| 64 | ut_ad(!is_owned()); |
| 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( |
| 77 | const Mutex* mutex, |
| 78 | const char* name, |
| 79 | unsigned line) |
| 80 | UNIV_NOTHROW |
| 81 | { |
| 82 | ut_ad(!is_owned()); |
| 83 | ut_ad(m_context.m_thread_id == ULINT_UNDEFINED); |
| 84 | |
| 85 | m_context.locked(mutex, name, line); |
| 86 | |
| 87 | sync_check_lock_granted(&m_context); |
| 88 | } |
| 89 | |
| 90 | template <typename Mutex> |
| 91 | void MutexDebug<Mutex>::release(const Mutex*) |
| 92 | UNIV_NOTHROW |
| 93 | { |
| 94 | ut_ad(is_owned()); |
| 95 | |
| 96 | m_context.release(); |
| 97 | |
| 98 | sync_check_unlock(&m_context); |
| 99 | } |
| 100 | |
| 101 | #endif /* UNIV_DEBUG */ |
| 102 | |