88// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99//
1010
11- private import Synchronization
12-
1311extension Runner {
1412 /// A type which collects the task-scoped runtime state for a running
1513 /// ``Runner`` instance, the tests it runs, and other objects it interacts
@@ -113,10 +111,7 @@ extension Configuration {
113111 /// - Returns: A unique number identifying `self` that can be
114112 /// passed to `_removeFromAll(identifiedBy:)`` to unregister it.
115113 private func _addToAll( ) -> UInt64 {
116- if deliverExpectationCheckedEvents, #available( _synchronizationAPI, * ) {
117- Self . _deliverExpectationCheckedEventsCount. add ( 1 , ordering: . sequentiallyConsistent)
118- }
119- return Self . _all. withLock { all in
114+ Self . _all. withLock { all in
120115 let id = all. nextID
121116 all. nextID += 1
122117 all. instances [ id] = self
@@ -128,37 +123,12 @@ extension Configuration {
128123 ///
129124 /// - Parameters:
130125 /// - id: The unique identifier of this instance, as previously returned by
131- /// `_addToAll()`.
132- private func _removeFromAll( identifiedBy id: UInt64 ) {
133- let configuration = Self . _all. withLock { all in
134- all. instances. removeValue ( forKey: id)
135- }
136- if let configuration, configuration. deliverExpectationCheckedEvents, #available( _synchronizationAPI, * ) {
137- Self . _deliverExpectationCheckedEventsCount. subtract ( 1 , ordering: . sequentiallyConsistent)
138- }
139- }
140-
141- /// An atomic counter that tracks the number of "current" configurations that
142- /// have set ``deliverExpectationCheckedEvents`` to `true`.
143- ///
144- /// On older Apple platforms, this property is not available and ``all`` is
145- /// directly consulted instead (which is less efficient.)
146- @available ( _synchronizationAPI, * )
147- private static let _deliverExpectationCheckedEventsCount = Atomic ( 0 )
148-
149- /// Whether or not events of the kind
150- /// ``Event/Kind-swift.enum/expectationChecked(_:)`` should be delivered to
151- /// the event handler of _any_ configuration set as current for a task in the
152- /// current process.
153- ///
154- /// To determine if an individual instance of ``Configuration`` is listening
155- /// for these events, consult the per-instance
156- /// ``Configuration/deliverExpectationCheckedEvents`` property.
157- static var deliverExpectationCheckedEvents : Bool {
158- if #available( _synchronizationAPI, * ) {
159- _deliverExpectationCheckedEventsCount. load ( ordering: . sequentiallyConsistent) > 0
160- } else {
161- all. contains ( where: \. deliverExpectationCheckedEvents)
126+ /// `_addToAll()`. If `nil`, this function has no effect.
127+ private func _removeFromAll( identifiedBy id: UInt64 ? ) {
128+ if let id {
129+ Self . _all. withLock { all in
130+ _ = all. instances. removeValue ( forKey: id)
131+ }
162132 }
163133 }
164134}
0 commit comments