~ubuntu-branches/ubuntu/precise/mysql-5.5/precise-201203300109

« back to all changes in this revision

Viewing changes to storage/perfschema/table_setup_timers.cc

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2011-11-08 11:31:13 UTC
  • Revision ID: package-import@ubuntu.com-20111108113113-3ulw01fvi4vn8m25
Tags: upstream-5.5.17
ImportĀ upstreamĀ versionĀ 5.5.17

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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_setup_timers.cc
 
18
  Table SETUP_TIMERS (implementation).
 
19
*/
 
20
 
 
21
#include "my_global.h"
 
22
#include "my_pthread.h"
 
23
#include "table_setup_timers.h"
 
24
#include "pfs_column_values.h"
 
25
#include "pfs_timer.h"
 
26
 
 
27
#define COUNT_SETUP_TIMERS 1
 
28
static row_setup_timers all_setup_timers_data[COUNT_SETUP_TIMERS]=
 
29
{
 
30
  {
 
31
    { C_STRING_WITH_LEN("wait") },
 
32
    &wait_timer
 
33
  }
 
34
};
 
35
 
 
36
THR_LOCK table_setup_timers::m_table_lock;
 
37
 
 
38
static const TABLE_FIELD_TYPE field_types[]=
 
39
{
 
40
  {
 
41
    { C_STRING_WITH_LEN("NAME") },
 
42
    { C_STRING_WITH_LEN("varchar(64)") },
 
43
    { NULL, 0}
 
44
  },
 
45
  {
 
46
    { C_STRING_WITH_LEN("TIMER_NAME") },
 
47
    { C_STRING_WITH_LEN("enum(\'CYCLE\',\'NANOSECOND\',\'MICROSECOND\',"
 
48
                        "\'MILLISECOND\',\'TICK\')") },
 
49
    { NULL, 0}
 
50
  }
 
51
};
 
52
 
 
53
TABLE_FIELD_DEF
 
54
table_setup_timers::m_field_def=
 
55
{ 2, field_types };
 
56
 
 
57
PFS_engine_table_share
 
58
table_setup_timers::m_share=
 
59
{
 
60
  { C_STRING_WITH_LEN("setup_timers") },
 
61
  &pfs_updatable_acl,
 
62
  &table_setup_timers::create,
 
63
  NULL, /* write_row */
 
64
  NULL, /* delete_all_rows */
 
65
  COUNT_SETUP_TIMERS,
 
66
  sizeof(PFS_simple_index),
 
67
  &m_table_lock,
 
68
  &m_field_def,
 
69
  false /* checked */
 
70
};
 
71
 
 
72
PFS_engine_table* table_setup_timers::create(void)
 
73
{
 
74
  return new table_setup_timers();
 
75
}
 
76
 
 
77
table_setup_timers::table_setup_timers()
 
78
  : PFS_engine_table(&m_share, &m_pos),
 
79
    m_row(NULL), m_pos(0), m_next_pos(0)
 
80
{}
 
81
 
 
82
void table_setup_timers::reset_position(void)
 
83
{
 
84
  m_pos.m_index= 0;
 
85
  m_next_pos.m_index= 0;
 
86
}
 
87
 
 
88
int table_setup_timers::rnd_next(void)
 
89
{
 
90
  int result;
 
91
 
 
92
  m_pos.set_at(&m_next_pos);
 
93
 
 
94
  if (m_pos.m_index < COUNT_SETUP_TIMERS)
 
95
  {
 
96
    m_row= &all_setup_timers_data[m_pos.m_index];
 
97
    m_next_pos.set_after(&m_pos);
 
98
    result= 0;
 
99
  }
 
100
  else
 
101
  {
 
102
    m_row= NULL;
 
103
    result= HA_ERR_END_OF_FILE;
 
104
  }
 
105
 
 
106
  return result;
 
107
}
 
108
 
 
109
int table_setup_timers::rnd_pos(const void *pos)
 
110
{
 
111
  set_position(pos);
 
112
  DBUG_ASSERT(m_pos.m_index < COUNT_SETUP_TIMERS);
 
113
  m_row= &all_setup_timers_data[m_pos.m_index];
 
114
  return 0;
 
115
}
 
116
 
 
117
int table_setup_timers::read_row_values(TABLE *table,
 
118
                                        unsigned char *,
 
119
                                        Field **fields,
 
120
                                        bool read_all)
 
121
{
 
122
  Field *f;
 
123
 
 
124
  DBUG_ASSERT(m_row);
 
125
 
 
126
  /* Set the null bits */
 
127
  DBUG_ASSERT(table->s->null_bytes == 0);
 
128
 
 
129
  for (; (f= *fields) ; fields++)
 
130
  {
 
131
    if (read_all || bitmap_is_set(table->read_set, f->field_index))
 
132
    {
 
133
      switch(f->field_index)
 
134
      {
 
135
      case 0: /* NAME */
 
136
        set_field_varchar_utf8(f, m_row->m_name.str, m_row->m_name.length);
 
137
        break;
 
138
      case 1: /* TIMER_NAME */
 
139
        set_field_enum(f, *(m_row->m_timer_name_ptr));
 
140
        break;
 
141
      default:
 
142
        DBUG_ASSERT(false);
 
143
      }
 
144
    }
 
145
  }
 
146
 
 
147
  return 0;
 
148
}
 
149
 
 
150
int table_setup_timers::update_row_values(TABLE *table,
 
151
                                          const unsigned char *,
 
152
                                          unsigned char *,
 
153
                                          Field **fields)
 
154
{
 
155
  Field *f;
 
156
  longlong value;
 
157
 
 
158
  DBUG_ASSERT(m_row);
 
159
 
 
160
  for (; (f= *fields) ; fields++)
 
161
  {
 
162
    if (bitmap_is_set(table->write_set, f->field_index))
 
163
    {
 
164
      switch(f->field_index)
 
165
      {
 
166
      case 0: /* NAME */
 
167
        return HA_ERR_WRONG_COMMAND;
 
168
      case 1: /* TIMER_NAME */
 
169
        value= get_field_enum(f);
 
170
        if ((value >= FIRST_TIMER_NAME) && (value <= LAST_TIMER_NAME))
 
171
          *(m_row->m_timer_name_ptr)= (enum_timer_name) value;
 
172
        else
 
173
          return HA_ERR_WRONG_COMMAND;
 
174
        break;
 
175
      default:
 
176
        DBUG_ASSERT(false);
 
177
      }
 
178
    }
 
179
  }
 
180
 
 
181
  return 0;
 
182
}
 
183