Skip to content

Commit fa33faf

Browse files
committed
[struct Atomic] Mark deinit as inlinable
1 parent 71b1dd6 commit fa33faf

File tree

1 file changed

+12
-233
lines changed

1 file changed

+12
-233
lines changed

Sources/Atomics/Atomic.swift

Lines changed: 12 additions & 233 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift Atomics open source project
44
//
5-
// Copyright (c) 2020 - 2023 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2023 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -13,6 +13,7 @@
1313
#if compiler(>=5.9) && $RawLayout
1414
import Builtin
1515

16+
/// An atomic value.
1617
@_rawLayout(like: Value.AtomicRepresentation)
1718
@frozen
1819
public struct Atomic<Value: AtomicValue>: ~Copyable
@@ -30,6 +31,16 @@ where Value.AtomicRepresentation.Value == Value
3031
_ptr.initialize(to: _Storage(initialValue))
3132
}
3233

34+
#if false // FIXME: This doesn't work correctly yet
35+
public consuming func destroy() -> Value {
36+
let value = _ptr.pointee.dispose()
37+
_ptr.deinitialize(count: 1)
38+
discard self // Doesn't yet work for raw layout types
39+
return value
40+
}
41+
#endif
42+
43+
@inlinable
3344
deinit {
3445
_ = _ptr.pointee.dispose()
3546
_ptr.deinitialize(count: 1)
@@ -251,236 +262,4 @@ extension Atomic {
251262
failureOrdering: failureOrdering)
252263
}
253264
}
254-
255-
extension Atomic where Value: AtomicInteger {
256-
/// Perform an atomic wrapping add operation and return the original value, applying
257-
/// the specified memory ordering.
258-
///
259-
/// Note: This operation silently wraps around on overflow, like the
260-
/// `&+` operator does on `Int` values.
261-
///
262-
/// - Parameter operand: An integer value.
263-
/// - Parameter ordering: The memory ordering to apply on this operation.
264-
/// - Returns: The original value before the operation.
265-
@_semantics("atomics.requires_constant_orderings")
266-
@_transparent @_alwaysEmitIntoClient
267-
public func loadThenWrappingIncrement(
268-
by operand: Value = 1,
269-
ordering: AtomicUpdateOrdering
270-
) -> Value {
271-
_Storage.atomicLoadThenWrappingIncrement(
272-
by: operand,
273-
at: _ptr,
274-
ordering: ordering)
275-
}
276-
/// Perform an atomic wrapping subtract operation and return the original value, applying
277-
/// the specified memory ordering.
278-
///
279-
/// Note: This operation silently wraps around on overflow, like the
280-
/// `&-` operator does on `Int` values.
281-
///
282-
/// - Parameter operand: An integer value.
283-
/// - Parameter ordering: The memory ordering to apply on this operation.
284-
/// - Returns: The original value before the operation.
285-
@_semantics("atomics.requires_constant_orderings")
286-
@_transparent @_alwaysEmitIntoClient
287-
public func loadThenWrappingDecrement(
288-
by operand: Value = 1,
289-
ordering: AtomicUpdateOrdering
290-
) -> Value {
291-
_Storage.atomicLoadThenWrappingDecrement(
292-
by: operand,
293-
at: _ptr,
294-
ordering: ordering)
295-
}
296-
/// Perform an atomic bitwise AND operation and return the original value, applying
297-
/// the specified memory ordering.
298-
///
299-
/// - Parameter operand: An integer value.
300-
/// - Parameter ordering: The memory ordering to apply on this operation.
301-
/// - Returns: The original value before the operation.
302-
@_semantics("atomics.requires_constant_orderings")
303-
@_transparent @_alwaysEmitIntoClient
304-
public func loadThenBitwiseAnd(
305-
with operand: Value,
306-
ordering: AtomicUpdateOrdering
307-
) -> Value {
308-
_Storage.atomicLoadThenBitwiseAnd(
309-
with: operand,
310-
at: _ptr,
311-
ordering: ordering)
312-
}
313-
/// Perform an atomic bitwise OR operation and return the original value, applying
314-
/// the specified memory ordering.
315-
///
316-
/// - Parameter operand: An integer value.
317-
/// - Parameter ordering: The memory ordering to apply on this operation.
318-
/// - Returns: The original value before the operation.
319-
@_semantics("atomics.requires_constant_orderings")
320-
@_transparent @_alwaysEmitIntoClient
321-
public func loadThenBitwiseOr(
322-
with operand: Value,
323-
ordering: AtomicUpdateOrdering
324-
) -> Value {
325-
_Storage.atomicLoadThenBitwiseOr(
326-
with: operand,
327-
at: _ptr,
328-
ordering: ordering)
329-
}
330-
/// Perform an atomic bitwise XOR operation and return the original value, applying
331-
/// the specified memory ordering.
332-
///
333-
/// - Parameter operand: An integer value.
334-
/// - Parameter ordering: The memory ordering to apply on this operation.
335-
/// - Returns: The original value before the operation.
336-
@_semantics("atomics.requires_constant_orderings")
337-
@_transparent @_alwaysEmitIntoClient
338-
public func loadThenBitwiseXor(
339-
with operand: Value,
340-
ordering: AtomicUpdateOrdering
341-
) -> Value {
342-
_Storage.atomicLoadThenBitwiseXor(
343-
with: operand,
344-
at: _ptr,
345-
ordering: ordering)
346-
}
347-
348-
/// Perform an atomic wrapping add operation and return the new value, applying
349-
/// the specified memory ordering.
350-
///
351-
/// Note: This operation silently wraps around on overflow, like the
352-
/// `&+` operator does on `Int` values.
353-
///
354-
/// - Parameter operand: An integer value.
355-
/// - Parameter ordering: The memory ordering to apply on this operation.
356-
/// - Returns: The new value after the operation.
357-
@_semantics("atomics.requires_constant_orderings")
358-
@_transparent @_alwaysEmitIntoClient
359-
public func wrappingIncrementThenLoad(
360-
by operand: Value = 1,
361-
ordering: AtomicUpdateOrdering
362-
) -> Value {
363-
let original = _Storage.atomicLoadThenWrappingIncrement(
364-
by: operand,
365-
at: _ptr,
366-
ordering: ordering)
367-
return original &+ operand
368-
}
369-
/// Perform an atomic wrapping subtract operation and return the new value, applying
370-
/// the specified memory ordering.
371-
///
372-
/// Note: This operation silently wraps around on overflow, like the
373-
/// `&-` operator does on `Int` values.
374-
///
375-
/// - Parameter operand: An integer value.
376-
/// - Parameter ordering: The memory ordering to apply on this operation.
377-
/// - Returns: The new value after the operation.
378-
@_semantics("atomics.requires_constant_orderings")
379-
@_transparent @_alwaysEmitIntoClient
380-
public func wrappingDecrementThenLoad(
381-
by operand: Value = 1,
382-
ordering: AtomicUpdateOrdering
383-
) -> Value {
384-
let original = _Storage.atomicLoadThenWrappingDecrement(
385-
by: operand,
386-
at: _ptr,
387-
ordering: ordering)
388-
return original &- operand
389-
}
390-
/// Perform an atomic bitwise AND operation and return the new value, applying
391-
/// the specified memory ordering.
392-
///
393-
/// - Parameter operand: An integer value.
394-
/// - Parameter ordering: The memory ordering to apply on this operation.
395-
/// - Returns: The new value after the operation.
396-
@_semantics("atomics.requires_constant_orderings")
397-
@_transparent @_alwaysEmitIntoClient
398-
public func bitwiseAndThenLoad(
399-
with operand: Value,
400-
ordering: AtomicUpdateOrdering
401-
) -> Value {
402-
let original = _Storage.atomicLoadThenBitwiseAnd(
403-
with: operand,
404-
at: _ptr,
405-
ordering: ordering)
406-
return original & operand
407-
}
408-
/// Perform an atomic bitwise OR operation and return the new value, applying
409-
/// the specified memory ordering.
410-
///
411-
/// - Parameter operand: An integer value.
412-
/// - Parameter ordering: The memory ordering to apply on this operation.
413-
/// - Returns: The new value after the operation.
414-
@_semantics("atomics.requires_constant_orderings")
415-
@_transparent @_alwaysEmitIntoClient
416-
public func bitwiseOrThenLoad(
417-
with operand: Value,
418-
ordering: AtomicUpdateOrdering
419-
) -> Value {
420-
let original = _Storage.atomicLoadThenBitwiseOr(
421-
with: operand,
422-
at: _ptr,
423-
ordering: ordering)
424-
return original | operand
425-
}
426-
/// Perform an atomic bitwise XOR operation and return the new value, applying
427-
/// the specified memory ordering.
428-
///
429-
/// - Parameter operand: An integer value.
430-
/// - Parameter ordering: The memory ordering to apply on this operation.
431-
/// - Returns: The new value after the operation.
432-
@_semantics("atomics.requires_constant_orderings")
433-
@_transparent @_alwaysEmitIntoClient
434-
public func bitwiseXorThenLoad(
435-
with operand: Value,
436-
ordering: AtomicUpdateOrdering
437-
) -> Value {
438-
let original = _Storage.atomicLoadThenBitwiseXor(
439-
with: operand,
440-
at: _ptr,
441-
ordering: ordering)
442-
return original ^ operand
443-
}
444-
445-
/// Perform an atomic wrapping increment operation applying the
446-
/// specified memory ordering.
447-
///
448-
/// Note: This operation silently wraps around on overflow, like the
449-
/// `&+=` operator does on `Int` values.
450-
///
451-
/// - Parameter operand: The value to add to the current value.
452-
/// - Parameter ordering: The memory ordering to apply on this operation.
453-
@_semantics("atomics.requires_constant_orderings")
454-
@_transparent @_alwaysEmitIntoClient
455-
public func wrappingIncrement(
456-
by operand: Value = 1,
457-
ordering: AtomicUpdateOrdering
458-
) {
459-
_ = _Storage.atomicLoadThenWrappingIncrement(
460-
by: operand,
461-
at: _ptr,
462-
ordering: ordering)
463-
}
464-
465-
/// Perform an atomic wrapping decrement operation applying the
466-
/// specified memory ordering.
467-
///
468-
/// Note: This operation silently wraps around on overflow, like the
469-
/// `&-=` operator does on `Int` values.
470-
///
471-
/// - Parameter operand: The value to subtract from the current value.
472-
/// - Parameter ordering: The memory ordering to apply on this operation.
473-
@_semantics("atomics.requires_constant_orderings")
474-
@_transparent @_alwaysEmitIntoClient
475-
public func wrappingDecrement(
476-
by operand: Value = 1,
477-
ordering: AtomicUpdateOrdering
478-
) {
479-
_ = _Storage.atomicLoadThenWrappingDecrement(
480-
by: operand,
481-
at: _ptr,
482-
ordering: ordering)
483-
}
484-
}
485-
486265
#endif

0 commit comments

Comments
 (0)