1 /* Copyright (c) 2010, 2012, 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, 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 21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ 22 23 #ifndef PFS_USER_H 24 #define PFS_USER_H 25 26 /** 27 @file storage/perfschema/pfs_user.h 28 Performance schema user (declarations). 29 */ 30 31 #include "pfs_lock.h" 32 #include "lf.h" 33 #include "pfs_con_slice.h" 34 35 struct PFS_global_param; 36 struct PFS_thread; 37 38 /** 39 @addtogroup Performance_schema_buffers 40 @{ 41 */ 42 43 struct PFS_user_key 44 { 45 /** 46 Hash search key. 47 This has to be a string for LF_HASH, 48 the format is "<username><0x00>" 49 */ 50 char m_hash_key[USERNAME_LENGTH + 1]; 51 uint m_key_length; 52 }; 53 54 struct PFS_ALIGNED PFS_user : public PFS_connection_slice 55 { 56 public: init_refcountPFS_user57 inline void init_refcount(void) 58 { 59 PFS_atomic::store_32(& m_refcount, 1); 60 } 61 get_refcountPFS_user62 inline int get_refcount(void) 63 { 64 return PFS_atomic::load_32(& m_refcount); 65 } 66 inc_refcountPFS_user67 inline void inc_refcount(void) 68 { 69 PFS_atomic::add_32(& m_refcount, 1); 70 } 71 dec_refcountPFS_user72 inline void dec_refcount(void) 73 { 74 PFS_atomic::add_32(& m_refcount, -1); 75 } 76 77 void aggregate(void); 78 void aggregate_waits(void); 79 void aggregate_stages(void); 80 void aggregate_statements(void); 81 void aggregate_stats(void); 82 void release(void); 83 84 /** Internal lock. */ 85 pfs_lock m_lock; 86 PFS_user_key m_key; 87 const char *m_username; 88 uint m_username_length; 89 90 ulonglong m_disconnected_count; 91 92 private: 93 int m_refcount; 94 }; 95 96 int init_user(const PFS_global_param *param); 97 void cleanup_user(void); 98 int init_user_hash(void); 99 void cleanup_user_hash(void); 100 101 PFS_user * 102 find_or_create_user(PFS_thread *thread, 103 const char *username, uint username_length); 104 105 PFS_user *sanitize_user(PFS_user *unsafe); 106 void purge_all_user(void); 107 108 109 /* For iterators and show status. */ 110 111 extern ulong user_max; 112 extern ulong user_lost; 113 114 /* Exposing the data directly, for iterators. */ 115 116 extern PFS_user *user_array; 117 118 extern LF_HASH user_hash; 119 120 /** @} */ 121 #endif 122 123