1/* Copyright (c) 2010, 2013, 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#ifndef PFS_HOST_H
17#define PFS_HOST_H
18
19/**
20 @file storage/perfschema/pfs_host.h
21 Performance schema host (declarations).
22*/
23
24#include "pfs_lock.h"
25#include "lf.h"
26#include "pfs_con_slice.h"
27
28struct PFS_global_param;
29struct PFS_thread;
30
31/**
32 @addtogroup Performance_schema_buffers
33 @{
34*/
35
36struct PFS_host_key
37{
38 /**
39 Hash search key.
40 This has to be a string for LF_HASH,
41 the format is "<hostname><0x00>"
42 */
43 char m_hash_key[HOSTNAME_LENGTH + 1];
44 uint m_key_length;
45};
46
47struct PFS_ALIGNED PFS_host : PFS_connection_slice
48{
49public:
50 inline void init_refcount(void)
51 {
52 PFS_atomic::store_32(& m_refcount, 1);
53 }
54
55 inline int get_refcount(void)
56 {
57 return PFS_atomic::load_32(& m_refcount);
58 }
59
60 inline void inc_refcount(void)
61 {
62 PFS_atomic::add_32(& m_refcount, 1);
63 }
64
65 inline void dec_refcount(void)
66 {
67 PFS_atomic::add_32(& m_refcount, -1);
68 }
69
70 void aggregate(void);
71 void aggregate_waits(void);
72 void aggregate_stages(void);
73 void aggregate_statements(void);
74 void aggregate_stats(void);
75 void release(void);
76
77 /* Internal lock. */
78 pfs_lock m_lock;
79 PFS_host_key m_key;
80 const char *m_hostname;
81 uint m_hostname_length;
82
83 ulonglong m_disconnected_count;
84
85private:
86 int m_refcount;
87};
88
89int init_host(const PFS_global_param *param);
90void cleanup_host(void);
91int init_host_hash(void);
92void cleanup_host_hash(void);
93
94PFS_host *find_or_create_host(PFS_thread *thread,
95 const char *hostname, uint hostname_length);
96
97PFS_host *sanitize_host(PFS_host *unsafe);
98void purge_all_host(void);
99
100/* For iterators and show status. */
101
102extern ulong host_max;
103extern ulong host_lost;
104
105/* Exposing the data directly, for iterators. */
106
107extern PFS_host *host_array;
108
109extern LF_HASH host_hash;
110
111/** @} */
112#endif
113
114