MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pfs_atomic.cc
Go to the documentation of this file.
1 /* Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software Foundation,
14  51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
15 
21 #include <my_global.h>
22 #include <my_pthread.h>
23 #include "pfs_atomic.h"
24 
25 /*
26  Using SAFE_MUTEX is impossible, because of recursion.
27  - code locks mutex X
28  - P_S records the event
29  - P_S needs an atomic counter A
30  - safe mutex called for m_mutex[hash(A)]
31  - safe mutex allocates/free memory
32  - safe mutex locks THR_LOCK_malloc
33  - P_S records the event
34  - P_S needs an atomic counter B
35  - safe mutex called for m_mutex[hash(B)]
36 
37  When hash(A) == hash(B), safe_mutex complains rightly that
38  the mutex is already locked.
39  In some cases, A == B, in particular for events_waits_history_long_index.
40 
41  In short, the implementation of PFS_atomic should not cause events
42  to be recorded in the performance schema.
43 
44  Also, because SAFE_MUTEX redefines pthread_mutex_t, etc,
45  this code is not inlined in pfs_atomic.h, but located here in pfs_atomic.cc.
46 
47  What is needed is a plain, unmodified, pthread_mutex_t.
48  This is provided by my_atomic_rwlock_t.
49 */
50 
61 my_atomic_rwlock_t PFS_atomic::m_rwlock_array[256];
62 
63 void PFS_atomic::init(void)
64 {
65  uint i;
66 
67  for (i=0; i< array_elements(m_rwlock_array); i++)
68  my_atomic_rwlock_init(&m_rwlock_array[i]);
69 }
70 
72 {
73  uint i;
74 
75  for (i=0; i< array_elements(m_rwlock_array); i++)
76  my_atomic_rwlock_destroy(&m_rwlock_array[i]);
77 }
78