Skip to content

Commit f14e9aa

Browse files
committed
Stop using _stdlib_AtomicInt in ThreadLocalStorage
1 parent bbc81ba commit f14e9aa

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

stdlib/public/core/ThreadLocalStorage.swift

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,33 @@ import SwiftShims
1515
// For testing purposes, a thread-safe counter to guarantee that destructors get
1616
// called by pthread.
1717
#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+
1840
public // @testable
19-
let _destroyTLSCounter = _stdlib_AtomicInt()
41+
func _loadDestroyTLSCounter() -> Int {
42+
return _destroyTLSCounter.load()
43+
}
44+
2045
#endif
2146

2247
// Thread local storage for all of the Swift standard library
@@ -124,7 +149,7 @@ internal func _destroyTLS(_ ptr: UnsafeMutableRawPointer?) {
124149

125150
#if INTERNAL_CHECKS_ENABLED
126151
// Log the fact we've destroyed our storage
127-
_destroyTLSCounter.fetchAndAdd(1)
152+
_destroyTLSCounter.increment()
128153
#endif
129154
}
130155

0 commit comments

Comments
 (0)