1 /* Copyright (c) 2009, 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 PFS_ATOMIC_H 24 #define PFS_ATOMIC_H 25 26 /** 27 @file storage/perfschema/pfs_atomic.h 28 Atomic operations (declarations). 29 */ 30 31 #include <my_atomic.h> 32 33 /** Helper for atomic operations. */ 34 class PFS_atomic 35 { 36 public: 37 /** Atomic load. */ load_32(int32 * ptr)38 static inline int32 load_32(int32 *ptr) 39 { 40 return my_atomic_load32(ptr); 41 } 42 43 /** Atomic load. */ load_64(int64 * ptr)44 static inline int64 load_64(int64 *ptr) 45 { 46 return my_atomic_load64(ptr); 47 } 48 49 /** Atomic load. */ load_u32(uint32 * ptr)50 static inline uint32 load_u32(uint32 *ptr) 51 { 52 return (uint32) my_atomic_load32((int32*) ptr); 53 } 54 55 /** Atomic load. */ load_u64(uint64 * ptr)56 static inline uint64 load_u64(uint64 *ptr) 57 { 58 return (uint64) my_atomic_load64((int64*) ptr); 59 } 60 61 /** Atomic store. */ store_32(int32 * ptr,int32 value)62 static inline void store_32(int32 *ptr, int32 value) 63 { 64 my_atomic_store32(ptr, value); 65 } 66 67 /** Atomic store. */ store_64(int64 * ptr,int64 value)68 static inline void store_64(int64 *ptr, int64 value) 69 { 70 my_atomic_store64(ptr, value); 71 } 72 73 /** Atomic store. */ store_u32(uint32 * ptr,uint32 value)74 static inline void store_u32(uint32 *ptr, uint32 value) 75 { 76 my_atomic_store32((int32*) ptr, (int32) value); 77 } 78 79 /** Atomic store. */ store_u64(uint64 * ptr,uint64 value)80 static inline void store_u64(uint64 *ptr, uint64 value) 81 { 82 my_atomic_store64((int64*) ptr, (int64) value); 83 } 84 85 /** Atomic add. */ add_32(int32 * ptr,int32 value)86 static inline int32 add_32(int32 *ptr, int32 value) 87 { 88 return my_atomic_add32(ptr, value); 89 } 90 91 /** Atomic add. */ add_64(int64 * ptr,int64 value)92 static inline int64 add_64(int64 *ptr, int64 value) 93 { 94 return my_atomic_add64(ptr, value); 95 } 96 97 /** Atomic add. */ add_u32(uint32 * ptr,uint32 value)98 static inline uint32 add_u32(uint32 *ptr, uint32 value) 99 { 100 return (uint32) my_atomic_add32((int32*) ptr, (int32) value); 101 } 102 103 /** Atomic add. */ add_u64(uint64 * ptr,uint64 value)104 static inline uint64 add_u64(uint64 *ptr, uint64 value) 105 { 106 return (uint64) my_atomic_add64((int64*) ptr, (int64) value); 107 } 108 109 /** Atomic compare and swap. */ cas_32(int32 * ptr,int32 * old_value,int32 new_value)110 static inline bool cas_32(int32 *ptr, int32 *old_value, 111 int32 new_value) 112 { 113 return my_atomic_cas32(ptr, old_value, new_value); 114 } 115 116 /** Atomic compare and swap. */ cas_64(int64 * ptr,int64 * old_value,int64 new_value)117 static inline bool cas_64(int64 *ptr, int64 *old_value, 118 int64 new_value) 119 { 120 return my_atomic_cas64(ptr, old_value, new_value); 121 } 122 123 /** Atomic compare and swap. */ cas_u32(uint32 * ptr,uint32 * old_value,uint32 new_value)124 static inline bool cas_u32(uint32 *ptr, uint32 *old_value, 125 uint32 new_value) 126 { 127 return my_atomic_cas32((int32*) ptr, (int32*) old_value, 128 (uint32) new_value); 129 } 130 131 /** Atomic compare and swap. */ cas_u64(uint64 * ptr,uint64 * old_value,uint64 new_value)132 static inline bool cas_u64(uint64 *ptr, uint64 *old_value, 133 uint64 new_value) 134 { 135 return my_atomic_cas64((int64*) ptr, (int64*) old_value, 136 (uint64) new_value); 137 } 138 }; 139 140 #endif 141 142