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