@@ -102,53 +102,24 @@ func _stdlib_atomicInitializeARCRef(
102
102
return wonRace
103
103
}
104
104
105
- % for bits in [ 32 , 64 ] :
106
- % for operation in [ 'Add', 'And', 'Or', 'Xor'] :
107
-
108
- // Warning: no overflow checking.
109
- @inlinable // FIXME(sil-serialize-all)
110
- internal func _swift_stdlib_atomicFetch${ operation} Int${ bits} (
111
- object target: UnsafeMutablePointer < Int ${ bits} > ,
112
- operand: Int ${ bits} ) - > Int${ bits} {
113
-
114
- let value = Builtin . atomicrmw_ ${ operation. lower ( ) } _seqcst_Int${ bits} (
115
- target. _rawValue, operand. _value)
116
-
117
- return Int ${ bits} ( value)
118
- }
119
-
120
- % end
121
- % end
122
-
123
- @inlinable // FIXME(sil-serialize-all)
124
- internal func _stdlib_atomicCompareExchangeStrongInt(
125
- object target: UnsafeMutablePointer < Int > ,
126
- expected: UnsafeMutablePointer < Int > ,
127
- desired: Int ) -> Bool {
128
- #if arch(i386) || arch(arm)
129
- let ( oldValue, won) = Builtin . cmpxchg_seqcst_seqcst_Int32 (
130
- target. _rawValue, expected. pointee. _value, desired. _value)
131
- #elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le) || arch(s390x)
132
- let ( oldValue, won) = Builtin . cmpxchg_seqcst_seqcst_Int64 (
133
- target. _rawValue, expected. pointee. _value, desired. _value)
134
- #endif
135
- expected. pointee. _value = oldValue
136
- return Bool ( won)
137
- }
138
-
139
- @inlinable // FIXME(sil-serialize-all)
140
- internal func _swift_stdlib_atomicStoreInt(
141
- object target: UnsafeMutablePointer < Int > ,
142
- desired: Int ) {
143
- #if arch(i386) || arch(arm)
144
- Builtin . atomicstore_seqcst_Int32 ( target. _rawValue, desired. _value)
145
- #elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le) || arch(s390x)
146
- Builtin . atomicstore_seqcst_Int64 ( target. _rawValue, desired. _value)
147
- #endif
105
+ @_transparent
106
+ public // @testable
107
+ func _stdlib_atomicLoadARCRef(
108
+ object target: UnsafeMutablePointer < AnyObject ? >
109
+ ) -> AnyObject ? {
110
+ let value = Builtin . atomicload_seqcst_Word ( target. _rawValue)
111
+ if let unwrapped = UnsafeRawPointer ( bitPattern: Int ( value) ) {
112
+ return Unmanaged < AnyObject > . fromOpaque ( unwrapped) . takeUnretainedValue ( )
113
+ }
114
+ return nil
148
115
}
149
116
150
- @_transparent
151
- public func _swift_stdlib_atomicLoadInt(
117
+ //===----------------------------------------------------------------------===//
118
+ // These pieces are used in ThreadLocalStorage.swift in debug builds.
119
+ // For tests, see similar functions from SwiftPrivate/AtomicInt.swift.gyb
120
+ //===----------------------------------------------------------------------===//
121
+ #if INTERNAL_CHECKS_ENABLED
122
+ internal func _swift_stdlib_atomicLoadInt(
152
123
object target: UnsafeMutablePointer < Int > ) -> Int {
153
124
#if arch(i386) || arch(arm)
154
125
let value = Builtin . atomicload_seqcst_Int32 ( target. _rawValue)
@@ -159,93 +130,40 @@ public func _swift_stdlib_atomicLoadInt(
159
130
#endif
160
131
}
161
132
162
- @_transparent
163
- public // @testable
164
- func _stdlib_atomicLoadARCRef(
165
- object target: UnsafeMutablePointer < AnyObject ? >
166
- ) -> AnyObject ? {
167
- let value = Builtin . atomicload_seqcst_Word ( target. _rawValue)
168
- if let unwrapped = UnsafeRawPointer ( bitPattern: Int ( value) ) {
169
- return Unmanaged < AnyObject > . fromOpaque ( unwrapped) . takeUnretainedValue ( )
170
- }
171
- return nil
172
- }
133
+ % for bits in [ 32 , 64 ] :
173
134
174
- % for operation in [ 'Add', 'And', 'Or', 'Xor'] :
175
135
// Warning: no overflow checking.
176
136
@inlinable // FIXME(sil-serialize-all)
177
- public func _swift_stdlib_atomicFetch${ operation} Int(
137
+ internal func _swift_stdlib_atomicFetchAddInt${ bits} (
138
+ object target: UnsafeMutablePointer < Int ${ bits} > ,
139
+ operand: Int ${ bits} ) - > Int${ bits} {
140
+
141
+ let value = Builtin . atomicrmw_add_seqcst_Int ${ bits} (
142
+ target. _rawValue, operand. _value)
143
+
144
+ return Int ${ bits} ( value)
145
+ }
146
+
147
+ % end
148
+
149
+ // Warning: no overflow checking.
150
+ internal func _swift_stdlib_atomicFetchAddInt(
178
151
object target: UnsafeMutablePointer < Int > ,
179
152
operand: Int ) -> Int {
180
153
let rawTarget = UnsafeMutableRawPointer ( target)
181
154
#if arch(i386) || arch(arm)
182
- let value = _swift_stdlib_atomicFetch $ { operation } Int32 (
155
+ let value = _swift_stdlib_atomicFetchAddInt32 (
183
156
object: rawTarget. assumingMemoryBound ( to: Int32 . self) ,
184
157
operand: Int32 ( operand) )
185
158
#elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le) || arch(s390x)
186
- let value = _swift_stdlib_atomicFetch $ { operation } Int64 (
159
+ let value = _swift_stdlib_atomicFetchAddInt64 (
187
160
object: rawTarget. assumingMemoryBound ( to: Int64 . self) ,
188
161
operand: Int64 ( operand) )
189
162
#endif
190
163
return Int ( value)
191
164
}
192
- % end
193
-
194
- @_fixed_layout // FIXME(sil-serialize-all)
195
- public final class _stdlib_AtomicInt {
196
- @usableFromInline // FIXME(sil-serialize-all)
197
- internal var _value : Int
198
-
199
- @inlinable // FIXME(sil-serialize-all)
200
- internal var _valuePtr : UnsafeMutablePointer < Int > {
201
- return _getUnsafePointerToStoredProperties ( self ) . assumingMemoryBound (
202
- to: Int . self)
203
- }
204
-
205
- @inlinable // FIXME(sil-serialize-all)
206
- public init ( _ value: Int = 0 ) {
207
- _value = value
208
- }
209
-
210
- @inlinable // FIXME(sil-serialize-all)
211
- deinit { }
212
-
213
- @inlinable // FIXME(sil-serialize-all)
214
- public func store( _ desired: Int ) {
215
- return _swift_stdlib_atomicStoreInt ( object: _valuePtr, desired: desired)
216
- }
217
-
218
- @inlinable // FIXME(sil-serialize-all)
219
- public func load( ) -> Int {
220
- return _swift_stdlib_atomicLoadInt ( object: _valuePtr)
221
- }
222
-
223
- % for operation_name, operation in [ ( 'Add', '+ ') , ( 'And', '& ') , ( 'Or', '|') , ( 'Xor', '^') ] :
224
- @inlinable // FIXME(sil-serialize-all)
225
- @discardableResult
226
- public func fetchAnd${ operation_name} ( _ operand: Int ) -> Int {
227
- return _swift_stdlib_atomicFetch ${ operation_name} Int(
228
- object: _valuePtr,
229
- operand: operand)
230
- }
231
-
232
- @inlinable // FIXME(sil-serialize-all)
233
- public func ${ operation_name. lower( ) } AndFetch( _ operand: Int) -> Int {
234
- return fetchAnd${ operation_name} ( operand) ${ operation} operand
235
- }
236
- % end
237
-
238
- @inlinable // FIXME(sil-serialize-all)
239
- public func compareExchange( expected: inout Int , desired: Int ) -> Bool {
240
- var expectedVar = expected
241
- let result = _stdlib_atomicCompareExchangeStrongInt (
242
- object: _valuePtr,
243
- expected: & expectedVar,
244
- desired: desired)
245
- expected = expectedVar
246
- return result
247
- }
248
- }
165
+ #endif // INTERNAL_CHECKS_ENABLED
166
+ //===----------------------------------------------------------------------===//
249
167
250
168
//===----------------------------------------------------------------------===//
251
169
// Conversion of primitive types to `String`
0 commit comments