1/***************************************************************************** 2 3Copyright (c) 2013, 2015, Oracle and/or its affiliates. All Rights Reserved. 4Copyright (c) 2017, MariaDB Corporation. 5 6This program is free software; you can redistribute it and/or modify it under 7the terms of the GNU General Public License as published by the Free Software 8Foundation; version 2 of the License. 9 10This program is distributed in the hope that it will be useful, but WITHOUT 11ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 13 14You should have received a copy of the GNU General Public License along with 15this program; if not, write to the Free Software Foundation, Inc., 1651 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA 17 18*****************************************************************************/ 19 20/******************************************************************//** 21@file include/sync0policy.ic 22Policy for mutexes. 23 24Created 2012-08-21 Sunny Bains. 25***********************************************************************/ 26 27#include "sync0debug.h" 28 29template <typename Mutex> 30std::string GenericPolicy<Mutex>::to_string() const 31{ 32 return(sync_mutex_to_string(get_id(), sync_file_created_get(this))); 33} 34 35template <typename Mutex> 36std::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 46template <typename Mutex> 47void 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 57template <typename Mutex> 58void 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 75template <typename Mutex> 76void 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 90template <typename Mutex> 91void 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