1 /* Copyright (c) 2016, 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 St, Fifth Floor, Boston, MA 02110-1301 USA */ 22 23 #ifndef CONNECTION_CONTROL_H 24 #define CONNECTION_CONTROL_H 25 26 #include <mysql/psi/mysql_thread.h> /* mysql_rwlock_t */ 27 28 #include "connection_control_data.h" 29 30 namespace connection_control 31 { 32 33 /** Helper class : Wrapper on READ lock */ 34 35 class RD_lock 36 { 37 public: RD_lock(mysql_rwlock_t * lock)38 explicit RD_lock(mysql_rwlock_t *lock) : m_lock(lock) 39 { 40 if (m_lock) 41 mysql_rwlock_rdlock(m_lock); 42 } ~RD_lock()43 ~RD_lock() 44 { 45 if (m_lock) 46 mysql_rwlock_unlock(m_lock); 47 } lock()48 void lock() 49 { 50 mysql_rwlock_rdlock(m_lock); 51 } unlock()52 void unlock() 53 { 54 mysql_rwlock_unlock(m_lock); 55 } 56 private: 57 mysql_rwlock_t *m_lock; 58 59 RD_lock(const RD_lock&); /* Not copyable. */ 60 void operator=(const RD_lock&); /* Not assignable. */ 61 }; 62 63 64 /** Helper class : Wrapper on write lock */ 65 66 class WR_lock 67 { 68 public: WR_lock(mysql_rwlock_t * lock)69 explicit WR_lock(mysql_rwlock_t *lock) : m_lock(lock) 70 { 71 if (m_lock) 72 mysql_rwlock_wrlock(m_lock); 73 } ~WR_lock()74 ~WR_lock() 75 { 76 if (m_lock) 77 mysql_rwlock_unlock(m_lock); 78 } lock()79 void lock() 80 { 81 mysql_rwlock_wrlock(m_lock); 82 } unlock()83 void unlock() 84 { 85 mysql_rwlock_unlock(m_lock); 86 } 87 private: 88 mysql_rwlock_t *m_lock; 89 90 WR_lock(const WR_lock&); /* Not copyable. */ 91 void operator=(const WR_lock&); /* Not assignable. */ 92 }; 93 } 94 #endif /* !CONNECTION_CONTROL_H */ 95