1/* Copyright (c) 2011, 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
14 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
15
16/**
17 @file storage/perfschema/cursor_by_thread.cc
18 Cursor CURSOR_BY_THREAD (implementation).
19*/
20
21#include "my_global.h"
22#include "cursor_by_thread.h"
23#include "pfs_instr.h"
24
25cursor_by_thread::cursor_by_thread(const PFS_engine_table_share *share)
26 : PFS_engine_table(share, &m_pos),
27 m_pos(0), m_next_pos(0)
28{}
29
30void cursor_by_thread::reset_position(void)
31{
32 m_pos.m_index= 0;
33 m_next_pos.m_index= 0;
34}
35
36int cursor_by_thread::rnd_next(void)
37{
38 PFS_thread *pfs;
39
40 for (m_pos.set_at(&m_next_pos);
41 m_pos.m_index < thread_max;
42 m_pos.next())
43 {
44 pfs= &thread_array[m_pos.m_index];
45 if (pfs->m_lock.is_populated())
46 {
47 make_row(pfs);
48 m_next_pos.set_after(&m_pos);
49 return 0;
50 }
51 }
52
53 return HA_ERR_END_OF_FILE;
54}
55
56int
57cursor_by_thread::rnd_pos(const void *pos)
58{
59 PFS_thread *pfs;
60
61 set_position(pos);
62 DBUG_ASSERT(m_pos.m_index < thread_max);
63 pfs= &thread_array[m_pos.m_index];
64 if (pfs->m_lock.is_populated())
65 {
66 make_row(pfs);
67 return 0;
68 }
69
70 return HA_ERR_RECORD_DELETED;
71}
72
73