1 /* Copyright (c) 2008, 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, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software Foundation,
21 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
22
23 /**
24 @file storage/perfschema/table_all_instr.cc
25 Abstract tables for all instruments (implementation).
26 */
27
28 #include "my_global.h"
29 #include "my_pthread.h"
30 #include "table_all_instr.h"
31 #include "pfs_global.h"
32
table_all_instr(const PFS_engine_table_share * share)33 table_all_instr::table_all_instr(const PFS_engine_table_share *share)
34 : PFS_engine_table(share, &m_pos),
35 m_pos(), m_next_pos()
36 {}
37
reset_position(void)38 void table_all_instr::reset_position(void)
39 {
40 m_pos.reset();
41 m_next_pos.reset();
42 }
43
rnd_next(void)44 int table_all_instr::rnd_next(void)
45 {
46 PFS_mutex *mutex;
47 PFS_rwlock *rwlock;
48 PFS_cond *cond;
49 PFS_file *file;
50 PFS_socket *socket;
51
52 for (m_pos.set_at(&m_next_pos);
53 m_pos.has_more_view();
54 m_pos.next_view())
55 {
56 switch (m_pos.m_index_1) {
57 case pos_all_instr::VIEW_MUTEX:
58 for ( ; m_pos.m_index_2 < mutex_max; m_pos.m_index_2++)
59 {
60 mutex= &mutex_array[m_pos.m_index_2];
61 if (mutex->m_lock.is_populated())
62 {
63 make_mutex_row(mutex);
64 m_next_pos.set_after(&m_pos);
65 return 0;
66 }
67 }
68 break;
69 case pos_all_instr::VIEW_RWLOCK:
70 for ( ; m_pos.m_index_2 < rwlock_max; m_pos.m_index_2++)
71 {
72 rwlock= &rwlock_array[m_pos.m_index_2];
73 if (rwlock->m_lock.is_populated())
74 {
75 make_rwlock_row(rwlock);
76 m_next_pos.set_after(&m_pos);
77 return 0;
78 }
79 }
80 break;
81 case pos_all_instr::VIEW_COND:
82 for ( ; m_pos.m_index_2 < cond_max; m_pos.m_index_2++)
83 {
84 cond= &cond_array[m_pos.m_index_2];
85 if (cond->m_lock.is_populated())
86 {
87 make_cond_row(cond);
88 m_next_pos.set_after(&m_pos);
89 return 0;
90 }
91 }
92 break;
93 case pos_all_instr::VIEW_FILE:
94 for ( ; m_pos.m_index_2 < file_max; m_pos.m_index_2++)
95 {
96 file= &file_array[m_pos.m_index_2];
97 if (file->m_lock.is_populated())
98 {
99 make_file_row(file);
100 m_next_pos.set_after(&m_pos);
101 return 0;
102 }
103 }
104 break;
105 case pos_all_instr::VIEW_SOCKET:
106 for ( ; m_pos.m_index_2 < socket_max; m_pos.m_index_2++)
107 {
108 socket= &socket_array[m_pos.m_index_2];
109 if (socket->m_lock.is_populated())
110 {
111 make_socket_row(socket);
112 m_next_pos.set_after(&m_pos);
113 return 0;
114 }
115 }
116 break;
117 }
118 }
119
120 return HA_ERR_END_OF_FILE;
121 }
122
rnd_pos(const void * pos)123 int table_all_instr::rnd_pos(const void *pos)
124 {
125 PFS_mutex *mutex;
126 PFS_rwlock *rwlock;
127 PFS_cond *cond;
128 PFS_file *file;
129 PFS_socket *socket;
130
131 set_position(pos);
132
133 switch (m_pos.m_index_1) {
134 case pos_all_instr::VIEW_MUTEX:
135 DBUG_ASSERT(m_pos.m_index_2 < mutex_max);
136 mutex= &mutex_array[m_pos.m_index_2];
137 if (mutex->m_lock.is_populated())
138 {
139 make_mutex_row(mutex);
140 return 0;
141 }
142 break;
143 case pos_all_instr::VIEW_RWLOCK:
144 DBUG_ASSERT(m_pos.m_index_2 < rwlock_max);
145 rwlock= &rwlock_array[m_pos.m_index_2];
146 if (rwlock->m_lock.is_populated())
147 {
148 make_rwlock_row(rwlock);
149 return 0;
150 }
151 break;
152 case pos_all_instr::VIEW_COND:
153 DBUG_ASSERT(m_pos.m_index_2 < cond_max);
154 cond= &cond_array[m_pos.m_index_2];
155 if (cond->m_lock.is_populated())
156 {
157 make_cond_row(cond);
158 return 0;
159 }
160 break;
161 case pos_all_instr::VIEW_FILE:
162 DBUG_ASSERT(m_pos.m_index_2 < file_max);
163 file= &file_array[m_pos.m_index_2];
164 if (file->m_lock.is_populated())
165 {
166 make_file_row(file);
167 return 0;
168 }
169 break;
170 case pos_all_instr::VIEW_SOCKET:
171 DBUG_ASSERT(m_pos.m_index_2 < socket_max);
172 socket= &socket_array[m_pos.m_index_2];
173 if (socket->m_lock.is_populated())
174 {
175 make_socket_row(socket);
176 return 0;
177 }
178 break;
179 }
180
181 return HA_ERR_RECORD_DELETED;
182 }
183