@@ -14,19 +14,17 @@ type Bool struct {
14
14
}
15
15
16
16
// Load atomically loads and returns the value stored in x.
17
- func (x * Bool ) Load () bool { return LoadUint32 (( * uint32 )( unsafe . Pointer ( x )) ) != 0 }
17
+ func (x * Bool ) Load () bool { return LoadUint32 (& x . v ) != 0 }
18
18
19
19
// Store atomically stores val into x.
20
- func (x * Bool ) Store (val bool ) { StoreUint32 (( * uint32 )( unsafe . Pointer ( x )) , b32 (val )) }
20
+ func (x * Bool ) Store (val bool ) { StoreUint32 (& x . v , b32 (val )) }
21
21
22
22
// Swap atomically stores new into x and returns the previous value.
23
- func (x * Bool ) Swap (new bool ) (old bool ) {
24
- return SwapUint32 ((* uint32 )(unsafe .Pointer (x )), b32 (new )) != 0
25
- }
23
+ func (x * Bool ) Swap (new bool ) (old bool ) { return SwapUint32 (& x .v , b32 (new )) != 0 }
26
24
27
25
// CompareAndSwap executes the compare-and-swap operation for the boolean value x.
28
26
func (x * Bool ) CompareAndSwap (old , new bool ) (swapped bool ) {
29
- return CompareAndSwapUint32 (( * uint32 )( unsafe . Pointer ( x )) , b32 (old ), b32 (new ))
27
+ return CompareAndSwapUint32 (& x . v , b32 (old ), b32 (new ))
30
28
}
31
29
32
30
// b32 returns a uint32 0 or 1 representing b.
@@ -48,21 +46,17 @@ type Pointer[T any] struct {
48
46
}
49
47
50
48
// Load atomically loads and returns the value stored in x.
51
- func (x * Pointer [T ]) Load () * T { return (* T )(LoadPointer (( * unsafe . Pointer )( unsafe . Pointer ( x )) )) }
49
+ func (x * Pointer [T ]) Load () * T { return (* T )(LoadPointer (& x . v )) }
52
50
53
51
// Store atomically stores val into x.
54
- func (x * Pointer [T ]) Store (val * T ) {
55
- StorePointer ((* unsafe .Pointer )(unsafe .Pointer (x )), unsafe .Pointer (val ))
56
- }
52
+ func (x * Pointer [T ]) Store (val * T ) { StorePointer (& x .v , unsafe .Pointer (val )) }
57
53
58
54
// Swap atomically stores new into x and returns the previous value.
59
- func (x * Pointer [T ]) Swap (new * T ) (old * T ) {
60
- return (* T )(SwapPointer ((* unsafe .Pointer )(unsafe .Pointer (x )), unsafe .Pointer (new )))
61
- }
55
+ func (x * Pointer [T ]) Swap (new * T ) (old * T ) { return (* T )(SwapPointer (& x .v , unsafe .Pointer (new ))) }
62
56
63
57
// CompareAndSwap executes the compare-and-swap operation for x.
64
58
func (x * Pointer [T ]) CompareAndSwap (old , new * T ) (swapped bool ) {
65
- return CompareAndSwapPointer (( * unsafe . Pointer )( unsafe . Pointer ( x )) , unsafe .Pointer (old ), unsafe .Pointer (new ))
59
+ return CompareAndSwapPointer (& x . v , unsafe .Pointer (old ), unsafe .Pointer (new ))
66
60
}
67
61
68
62
// An Int32 is an atomic int32. The zero value is zero.
@@ -72,21 +66,21 @@ type Int32 struct {
72
66
}
73
67
74
68
// Load atomically loads and returns the value stored in x.
75
- func (x * Int32 ) Load () int32 { return LoadInt32 (( * int32 )( unsafe . Pointer ( x )) ) }
69
+ func (x * Int32 ) Load () int32 { return LoadInt32 (& x . v ) }
76
70
77
71
// Store atomically stores val into x.
78
- func (x * Int32 ) Store (val int32 ) { StoreInt32 (( * int32 )( unsafe . Pointer ( x )) , val ) }
72
+ func (x * Int32 ) Store (val int32 ) { StoreInt32 (& x . v , val ) }
79
73
80
74
// Swap atomically stores new into x and returns the previous value.
81
- func (x * Int32 ) Swap (new int32 ) (old int32 ) { return SwapInt32 (( * int32 )( unsafe . Pointer ( x )) , new ) }
75
+ func (x * Int32 ) Swap (new int32 ) (old int32 ) { return SwapInt32 (& x . v , new ) }
82
76
83
77
// CompareAndSwap executes the compare-and-swap operation for x.
84
78
func (x * Int32 ) CompareAndSwap (old , new int32 ) (swapped bool ) {
85
- return CompareAndSwapInt32 (( * int32 )( unsafe . Pointer ( x )) , old , new )
79
+ return CompareAndSwapInt32 (& x . v , old , new )
86
80
}
87
81
88
82
// Add atomically adds delta to x and returns the new value.
89
- func (x * Int32 ) Add (delta int32 ) (new int32 ) { return AddInt32 (( * int32 )( unsafe . Pointer ( x )) , delta ) }
83
+ func (x * Int32 ) Add (delta int32 ) (new int32 ) { return AddInt32 (& x . v , delta ) }
90
84
91
85
// An Int64 is an atomic int64. The zero value is zero.
92
86
type Int64 struct {
@@ -96,21 +90,21 @@ type Int64 struct {
96
90
}
97
91
98
92
// Load atomically loads and returns the value stored in x.
99
- func (x * Int64 ) Load () int64 { return LoadInt64 (( * int64 )( unsafe . Pointer ( x )) ) }
93
+ func (x * Int64 ) Load () int64 { return LoadInt64 (& x . v ) }
100
94
101
95
// Store atomically stores val into x.
102
- func (x * Int64 ) Store (val int64 ) { StoreInt64 (( * int64 )( unsafe . Pointer ( x )) , val ) }
96
+ func (x * Int64 ) Store (val int64 ) { StoreInt64 (& x . v , val ) }
103
97
104
98
// Swap atomically stores new into x and returns the previous value.
105
- func (x * Int64 ) Swap (new int64 ) (old int64 ) { return SwapInt64 (( * int64 )( unsafe . Pointer ( x )) , new ) }
99
+ func (x * Int64 ) Swap (new int64 ) (old int64 ) { return SwapInt64 (& x . v , new ) }
106
100
107
101
// CompareAndSwap executes the compare-and-swap operation for x.
108
102
func (x * Int64 ) CompareAndSwap (old , new int64 ) (swapped bool ) {
109
- return CompareAndSwapInt64 (( * int64 )( unsafe . Pointer ( x )) , old , new )
103
+ return CompareAndSwapInt64 (& x . v , old , new )
110
104
}
111
105
112
106
// Add atomically adds delta to x and returns the new value.
113
- func (x * Int64 ) Add (delta int64 ) (new int64 ) { return AddInt64 (( * int64 )( unsafe . Pointer ( x )) , delta ) }
107
+ func (x * Int64 ) Add (delta int64 ) (new int64 ) { return AddInt64 (& x . v , delta ) }
114
108
115
109
// An Uint32 is an atomic uint32. The zero value is zero.
116
110
type Uint32 struct {
@@ -119,23 +113,21 @@ type Uint32 struct {
119
113
}
120
114
121
115
// Load atomically loads and returns the value stored in x.
122
- func (x * Uint32 ) Load () uint32 { return LoadUint32 (( * uint32 )( unsafe . Pointer ( x )) ) }
116
+ func (x * Uint32 ) Load () uint32 { return LoadUint32 (& x . v ) }
123
117
124
118
// Store atomically stores val into x.
125
- func (x * Uint32 ) Store (val uint32 ) { StoreUint32 (( * uint32 )( unsafe . Pointer ( x )) , val ) }
119
+ func (x * Uint32 ) Store (val uint32 ) { StoreUint32 (& x . v , val ) }
126
120
127
121
// Swap atomically stores new into x and returns the previous value.
128
- func (x * Uint32 ) Swap (new uint32 ) (old uint32 ) { return SwapUint32 (( * uint32 )( unsafe . Pointer ( x )) , new ) }
122
+ func (x * Uint32 ) Swap (new uint32 ) (old uint32 ) { return SwapUint32 (& x . v , new ) }
129
123
130
124
// CompareAndSwap executes the compare-and-swap operation for x.
131
125
func (x * Uint32 ) CompareAndSwap (old , new uint32 ) (swapped bool ) {
132
- return CompareAndSwapUint32 (( * uint32 )( unsafe . Pointer ( x )) , old , new )
126
+ return CompareAndSwapUint32 (& x . v , old , new )
133
127
}
134
128
135
129
// Add atomically adds delta to x and returns the new value.
136
- func (x * Uint32 ) Add (delta uint32 ) (new uint32 ) {
137
- return AddUint32 ((* uint32 )(unsafe .Pointer (x )), delta )
138
- }
130
+ func (x * Uint32 ) Add (delta uint32 ) (new uint32 ) { return AddUint32 (& x .v , delta ) }
139
131
140
132
// An Uint64 is an atomic uint64. The zero value is zero.
141
133
type Uint64 struct {
@@ -145,23 +137,21 @@ type Uint64 struct {
145
137
}
146
138
147
139
// Load atomically loads and returns the value stored in x.
148
- func (x * Uint64 ) Load () uint64 { return LoadUint64 (( * uint64 )( unsafe . Pointer ( x )) ) }
140
+ func (x * Uint64 ) Load () uint64 { return LoadUint64 (& x . v ) }
149
141
150
142
// Store atomically stores val into x.
151
- func (x * Uint64 ) Store (val uint64 ) { StoreUint64 (( * uint64 )( unsafe . Pointer ( x )) , val ) }
143
+ func (x * Uint64 ) Store (val uint64 ) { StoreUint64 (& x . v , val ) }
152
144
153
145
// Swap atomically stores new into x and returns the previous value.
154
- func (x * Uint64 ) Swap (new uint64 ) (old uint64 ) { return SwapUint64 (( * uint64 )( unsafe . Pointer ( x )) , new ) }
146
+ func (x * Uint64 ) Swap (new uint64 ) (old uint64 ) { return SwapUint64 (& x . v , new ) }
155
147
156
148
// CompareAndSwap executes the compare-and-swap operation for x.
157
149
func (x * Uint64 ) CompareAndSwap (old , new uint64 ) (swapped bool ) {
158
- return CompareAndSwapUint64 (( * uint64 )( unsafe . Pointer ( x )) , old , new )
150
+ return CompareAndSwapUint64 (& x . v , old , new )
159
151
}
160
152
161
153
// Add atomically adds delta to x and returns the new value.
162
- func (x * Uint64 ) Add (delta uint64 ) (new uint64 ) {
163
- return AddUint64 ((* uint64 )(unsafe .Pointer (x )), delta )
164
- }
154
+ func (x * Uint64 ) Add (delta uint64 ) (new uint64 ) { return AddUint64 (& x .v , delta ) }
165
155
166
156
// An Uintptr is an atomic uintptr. The zero value is zero.
167
157
type Uintptr struct {
@@ -170,25 +160,21 @@ type Uintptr struct {
170
160
}
171
161
172
162
// Load atomically loads and returns the value stored in x.
173
- func (x * Uintptr ) Load () uintptr { return LoadUintptr (( * uintptr )( unsafe . Pointer ( x )) ) }
163
+ func (x * Uintptr ) Load () uintptr { return LoadUintptr (& x . v ) }
174
164
175
165
// Store atomically stores val into x.
176
- func (x * Uintptr ) Store (val uintptr ) { StoreUintptr (( * uintptr )( unsafe . Pointer ( x )) , val ) }
166
+ func (x * Uintptr ) Store (val uintptr ) { StoreUintptr (& x . v , val ) }
177
167
178
168
// Swap atomically stores new into x and returns the previous value.
179
- func (x * Uintptr ) Swap (new uintptr ) (old uintptr ) {
180
- return SwapUintptr ((* uintptr )(unsafe .Pointer (x )), new )
181
- }
169
+ func (x * Uintptr ) Swap (new uintptr ) (old uintptr ) { return SwapUintptr (& x .v , new ) }
182
170
183
171
// CompareAndSwap executes the compare-and-swap operation for x.
184
172
func (x * Uintptr ) CompareAndSwap (old , new uintptr ) (swapped bool ) {
185
- return CompareAndSwapUintptr (( * uintptr )( unsafe . Pointer ( x )) , old , new )
173
+ return CompareAndSwapUintptr (& x . v , old , new )
186
174
}
187
175
188
176
// Add atomically adds delta to x and returns the new value.
189
- func (x * Uintptr ) Add (delta uintptr ) (new uintptr ) {
190
- return AddUintptr ((* uintptr )(unsafe .Pointer (x )), delta )
191
- }
177
+ func (x * Uintptr ) Add (delta uintptr ) (new uintptr ) { return AddUintptr (& x .v , delta ) }
192
178
193
179
// noCopy may be added to structs which must not be copied
194
180
// after the first use.
0 commit comments