File tree Expand file tree Collapse file tree 1 file changed +27
-2
lines changed Expand file tree Collapse file tree 1 file changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -15,8 +15,33 @@ import SwiftShims
15
15
// For testing purposes, a thread-safe counter to guarantee that destructors get
16
16
// called by pthread.
17
17
#if INTERNAL_CHECKS_ENABLED
18
+ internal class _TLSAtomicInt {
19
+ internal var value : Int
20
+ internal init ( ) { self . value = 0 }
21
+
22
+ internal var valuePtr : UnsafeMutablePointer < Int > {
23
+ return _getUnsafePointerToStoredProperties ( self ) . assumingMemoryBound (
24
+ to: Int . self)
25
+ }
26
+
27
+ internal func increment( ) {
28
+ _ = _swift_stdlib_atomicFetchAddInt (
29
+ object: valuePtr,
30
+ operand: 1 )
31
+ }
32
+
33
+ internal func load( ) -> Int {
34
+ return _swift_stdlib_atomicLoadInt ( object: valuePtr)
35
+ }
36
+ }
37
+
38
+ internal let _destroyTLSCounter = _TLSAtomicInt ( )
39
+
18
40
public // @testable
19
- let _destroyTLSCounter = _stdlib_AtomicInt ( )
41
+ func _loadDestroyTLSCounter( ) -> Int {
42
+ return _destroyTLSCounter. load ( )
43
+ }
44
+
20
45
#endif
21
46
22
47
// Thread local storage for all of the Swift standard library
@@ -124,7 +149,7 @@ internal func _destroyTLS(_ ptr: UnsafeMutableRawPointer?) {
124
149
125
150
#if INTERNAL_CHECKS_ENABLED
126
151
// Log the fact we've destroyed our storage
127
- _destroyTLSCounter. fetchAndAdd ( 1 )
152
+ _destroyTLSCounter. increment ( )
128
153
#endif
129
154
}
130
155
You can’t perform that action at this time.
0 commit comments