-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathUnmanaged extensions.swift
50 lines (44 loc) · 1.82 KB
/
Unmanaged extensions.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Atomics open source project
//
// Copyright (c) 2020 - 2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#if ATOMICS_SINGLE_MODULE
@_silgen_name("_sa_retain_n")
internal func _sa_retain_n(_ object: UnsafeMutableRawPointer, _ delta: UInt32)
@_silgen_name("_sa_release_n")
internal func _sa_release_n(_ object: UnsafeMutableRawPointer, _ delta: UInt32)
#else
// Note: with ATOMICS_NATIVE_BUILTINS, this file contains the last remaining
// import of the shims module, and we only need it to get the declarations for
// _sa_retain_n/_sa_release_n. The import is unfortunately still problematic;
// these functions need to be moved into the stdlib or (preferably) we need
// a compiler-level fix for https://github.com/apple/swift/issues/56105 to get rid
// of it.
//
// Hiding the import using @_implementationOnly is not possible unless
// Swift's library evolution dialect is enabled. (Which we cannot easily test
// here.) Perhaps `internal import` will help work around this at some point.
import _AtomicsShims
#endif
extension Unmanaged {
internal func retain(by delta: Int) {
_sa_retain_n(toOpaque(), UInt32(delta))
}
internal func release(by delta: Int) {
_sa_release_n(toOpaque(), UInt32(delta))
}
}
extension Unmanaged {
@inline(__always)
internal static func passRetained(_ instance: __owned Instance?) -> Self? {
guard let instance = instance else { return nil }
return .passRetained(instance)
}
}