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 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
16/**
17 @file storage/perfschema/table_all_instr.cc
18 Abstract tables for all instruments (implementation).
19*/
20
21#include "my_global.h"
22#include "my_pthread.h"
23#include "table_all_instr.h"
24#include "pfs_global.h"
25
26table_all_instr::table_all_instr(const PFS_engine_table_share *share)
27 : PFS_engine_table(share, &m_pos),
28 m_pos(), m_next_pos()
29{}
30
31void table_all_instr::reset_position(void)
32{
33 m_pos.reset();
34 m_next_pos.reset();
35}
36
37int table_all_instr::rnd_next(void)
38{
39 PFS_mutex *mutex;
40 PFS_rwlock *rwlock;
41 PFS_cond *cond;
42 PFS_file *file;
43 PFS_socket *socket;
44
45 for (m_pos.set_at(&m_next_pos);
46 m_pos.has_more_view();
47 m_pos.next_view())
48 {
49 switch (m_pos.m_index_1) {
50 case pos_all_instr::VIEW_MUTEX:
51 for ( ; m_pos.m_index_2 < mutex_max; m_pos.m_index_2++)
52 {
53 mutex= &mutex_array[m_pos.m_index_2];
54 if (mutex->m_lock.is_populated())
55 {
56 make_mutex_row(mutex);
57 m_next_pos.set_after(&m_pos);
58 return 0;
59 }
60 }
61 break;
62 case pos_all_instr::VIEW_RWLOCK:
63 for ( ; m_pos.m_index_2 < rwlock_max; m_pos.m_index_2++)
64 {
65 rwlock= &rwlock_array[m_pos.m_index_2];
66 if (rwlock->m_lock.is_populated())
67 {
68 make_rwlock_row(rwlock);
69 m_next_pos.set_after(&m_pos);
70 return 0;
71 }
72 }
73 break;
74 case pos_all_instr::VIEW_COND:
75 for ( ; m_pos.m_index_2 < cond_max; m_pos.m_index_2++)
76 {
77 cond= &cond_array[m_pos.m_index_2];
78 if (cond->m_lock.is_populated())
79 {
80 make_cond_row(cond);
81 m_next_pos.set_after(&m_pos);
82 return 0;
83 }
84 }
85 break;
86 case pos_all_instr::VIEW_FILE:
87 for ( ; m_pos.m_index_2 < file_max; m_pos.m_index_2++)
88 {
89 file= &file_array[m_pos.m_index_2];
90 if (file->m_lock.is_populated())
91 {
92 make_file_row(file);
93 m_next_pos.set_after(&m_pos);
94 return 0;
95 }
96 }
97 break;
98 case pos_all_instr::VIEW_SOCKET:
99 for ( ; m_pos.m_index_2 < socket_max; m_pos.m_index_2++)
100 {
101 socket= &socket_array[m_pos.m_index_2];
102 if (socket->m_lock.is_populated())
103 {
104 make_socket_row(socket);
105 m_next_pos.set_after(&m_pos);
106 return 0;
107 }
108 }
109 break;
110 }
111 }
112
113 return HA_ERR_END_OF_FILE;
114}
115
116int table_all_instr::rnd_pos(const void *pos)
117{
118 PFS_mutex *mutex;
119 PFS_rwlock *rwlock;
120 PFS_cond *cond;
121 PFS_file *file;
122 PFS_socket *socket;
123
124 set_position(pos);
125
126 switch (m_pos.m_index_1) {
127 case pos_all_instr::VIEW_MUTEX:
128 DBUG_ASSERT(m_pos.m_index_2 < mutex_max);
129 mutex= &mutex_array[m_pos.m_index_2];
130 if (mutex->m_lock.is_populated())
131 {
132 make_mutex_row(mutex);
133 return 0;
134 }
135 break;
136 case pos_all_instr::VIEW_RWLOCK:
137 DBUG_ASSERT(m_pos.m_index_2 < rwlock_max);
138 rwlock= &rwlock_array[m_pos.m_index_2];
139 if (rwlock->m_lock.is_populated())
140 {
141 make_rwlock_row(rwlock);
142 return 0;
143 }
144 break;
145 case pos_all_instr::VIEW_COND:
146 DBUG_ASSERT(m_pos.m_index_2 < cond_max);
147 cond= &cond_array[m_pos.m_index_2];
148 if (cond->m_lock.is_populated())
149 {
150 make_cond_row(cond);
151 return 0;
152 }
153 break;
154 case pos_all_instr::VIEW_FILE:
155 DBUG_ASSERT(m_pos.m_index_2 < file_max);
156 file= &file_array[m_pos.m_index_2];
157 if (file->m_lock.is_populated())
158 {
159 make_file_row(file);
160 return 0;
161 }
162 break;
163 case pos_all_instr::VIEW_SOCKET:
164 DBUG_ASSERT(m_pos.m_index_2 < socket_max);
165 socket= &socket_array[m_pos.m_index_2];
166 if (socket->m_lock.is_populated())
167 {
168 make_socket_row(socket);
169 return 0;
170 }
171 break;
172 }
173
174 return HA_ERR_RECORD_DELETED;
175}
176