1 /* Copyright (c) 2008, 2021, Oracle and/or its affiliates.
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 #ifndef TABLE_SYNC_INSTANCE_H
24 #define TABLE_SYNC_INSTANCE_H
25 
26 /**
27   @file storage/perfschema/table_sync_instances.h
28   Table MUTEX_INSTANCES, RWLOCK_INSTANCES and COND_INSTANCES (declarations).
29 */
30 
31 #include "pfs_column_types.h"
32 #include "pfs_engine_table.h"
33 
34 struct PFS_mutex;
35 struct PFS_rwlock;
36 struct PFS_cond;
37 
38 /**
39   @addtogroup Performance_schema_tables
40   @{
41 */
42 
43 /** A row of table PERFORMANCE_SCHEMA.MUTEX_INSTANCES. */
44 struct row_mutex_instances
45 {
46   /** Column NAME. */
47   const char *m_name;
48   /** Length in bytes of @c m_name. */
49   uint m_name_length;
50   /** Column OBJECT_INSTANCE_BEGIN. */
51   const void *m_identity;
52   /** True if column LOCKED_BY_THREAD_ID is not null. */
53   bool m_locked;
54   /** Column LOCKED_BY_THREAD_ID. */
55   ulonglong m_locked_by_thread_id;
56 };
57 
58 /** Table PERFORMANCE_SCHEMA.MUTEX_INSTANCES. */
59 class table_mutex_instances : public PFS_engine_table
60 {
61 public:
62   /** Table share. */
63   static PFS_engine_table_share m_share;
64   static PFS_engine_table* create();
65   static ha_rows get_row_count();
66 
67   virtual int rnd_next();
68   virtual int rnd_pos(const void *pos);
69   virtual void reset_position(void);
70 
71 private:
72   virtual int read_row_values(TABLE *table,
73                               unsigned char *buf,
74                               Field **fields,
75                               bool read_all);
76 
77   table_mutex_instances();
78 
79 public:
~table_mutex_instances()80   ~table_mutex_instances()
81   {}
82 
83 private:
84   void make_row(PFS_mutex *pfs);
85 
86   /** Table share lock. */
87   static THR_LOCK m_table_lock;
88   /** Fields definition. */
89   static TABLE_FIELD_DEF m_field_def;
90 
91   /** Current row. */
92   row_mutex_instances m_row;
93   /** True if the current row exists. */
94   bool m_row_exists;
95   /** Current position. */
96   PFS_simple_index m_pos;
97   /** Next position. */
98   PFS_simple_index m_next_pos;
99 };
100 
101 /** A row of table PERFORMANCE_SCHEMA.RWLOCK_INSTANCES. */
102 struct row_rwlock_instances
103 {
104   /** Column NAME. */
105   const char *m_name;
106   /** Length in bytes of @c m_name. */
107   uint m_name_length;
108   /** Column OBJECT_INSTANCE_BEGIN. */
109   const void *m_identity;
110   /** True if column WRITE_LOCKED_BY_THREAD_ID is not null. */
111   bool m_write_locked;
112   /** Column WRITE_LOCKED_BY_THREAD_ID. */
113   ulonglong m_write_locked_by_thread_id;
114   /** Column READ_LOCKED_BY_COUNT. */
115   ulong m_readers;
116 };
117 
118 /** Table PERFORMANCE_SCHEMA.RWLOCK_INSTANCES. */
119 class table_rwlock_instances : public PFS_engine_table
120 {
121 public:
122   /** Table share */
123   static PFS_engine_table_share m_share;
124   static PFS_engine_table* create();
125   static ha_rows get_row_count();
126 
127   virtual int rnd_next();
128   virtual int rnd_pos(const void *pos);
129   virtual void reset_position(void);
130 
131 private:
132   virtual int read_row_values(TABLE *table,
133                               unsigned char *buf,
134                               Field **fields,
135                               bool read_all);
136 
137   table_rwlock_instances();
138 
139 public:
~table_rwlock_instances()140   ~table_rwlock_instances()
141   {}
142 
143 private:
144   void make_row(PFS_rwlock *pfs);
145 
146   /** Table share lock. */
147   static THR_LOCK m_table_lock;
148   /** Fields definition. */
149   static TABLE_FIELD_DEF m_field_def;
150 
151   /** Current row. */
152   row_rwlock_instances m_row;
153   /** True if the current row exists. */
154   bool m_row_exists;
155   /** Current position. */
156   PFS_simple_index m_pos;
157   /** Next position. */
158   PFS_simple_index m_next_pos;
159 };
160 
161 /** A row of table PERFORMANCE_SCHEMA.COND_INSTANCES. */
162 struct row_cond_instances
163 {
164   /** Column NAME. */
165   const char *m_name;
166   /** Length in bytes of @c m_name. */
167   uint m_name_length;
168   /** Column OBJECT_INSTANCE_BEGIN. */
169   const void *m_identity;
170 };
171 
172 /** Table PERFORMANCE_SCHEMA.COND_INSTANCES. */
173 class table_cond_instances : public PFS_engine_table
174 {
175 public:
176   /** Table share. */
177   static PFS_engine_table_share m_share;
178   static PFS_engine_table* create();
179   static ha_rows get_row_count();
180 
181   virtual int rnd_next();
182   virtual int rnd_pos(const void *pos);
183   virtual void reset_position(void);
184 
185 private:
186   virtual int read_row_values(TABLE *table,
187                               unsigned char *buf,
188                               Field **fields,
189                               bool read_all);
190 
191   table_cond_instances();
192 
193 public:
~table_cond_instances()194   ~table_cond_instances()
195   {}
196 
197 private:
198   void make_row(PFS_cond *pfs);
199 
200   /** Table share lock. */
201   static THR_LOCK m_table_lock;
202   /** Fields definition. */
203   static TABLE_FIELD_DEF m_field_def;
204 
205   /** Current row. */
206   row_cond_instances m_row;
207   /** True if the current row exists. */
208   bool m_row_exists;
209   /** Current position. */
210   PFS_simple_index m_pos;
211   /** Next position. */
212   PFS_simple_index m_next_pos;
213 };
214 
215 /** @} */
216 #endif
217