File tree Expand file tree Collapse file tree 3 files changed +17
-15
lines changed Expand file tree Collapse file tree 3 files changed +17
-15
lines changed Original file line number Diff line number Diff line change @@ -279,18 +279,20 @@ final class CrashRecoveryTests: XCTestCase {
279
279
let clangdRestartedFirstTime = self . expectation ( description: " clangd restarted for the first time " )
280
280
let clangdRestartedSecondTime = self . expectation ( description: " clangd restarted for the second time " )
281
281
282
- var clangdHasRestartedFirstTime = false
282
+ let clangdHasRestartedFirstTime = ThreadSafeBox ( initialValue : false )
283
283
284
284
await clangdServer. addStateChangeHandler { ( oldState, newState) in
285
285
switch newState {
286
286
case . connectionInterrupted:
287
287
clangdCrashed. fulfill ( )
288
288
case . connected:
289
- if !clangdHasRestartedFirstTime {
290
- clangdRestartedFirstTime. fulfill ( )
291
- clangdHasRestartedFirstTime = true
292
- } else {
293
- clangdRestartedSecondTime. fulfill ( )
289
+ clangdHasRestartedFirstTime. withLock { clangdHasRestartedFirstTime in
290
+ if !clangdHasRestartedFirstTime {
291
+ clangdRestartedFirstTime. fulfill ( )
292
+ clangdHasRestartedFirstTime = true
293
+ } else {
294
+ clangdRestartedSecondTime. fulfill ( )
295
+ }
294
296
}
295
297
default :
296
298
break
Original file line number Diff line number Diff line change 10
10
//
11
11
//===----------------------------------------------------------------------===//
12
12
13
+ import CAtomics
13
14
import LSPTestSupport
14
15
import SourceKitD
15
16
import TSCBasic
@@ -40,7 +41,7 @@ final class SourceKitDRegistryTests: XCTestCase {
40
41
let registry = SourceKitDRegistry ( )
41
42
42
43
@inline ( never)
43
- func scope( registry: SourceKitDRegistry ) async throws -> Int {
44
+ func scope( registry: SourceKitDRegistry ) async throws -> UInt32 {
44
45
let a = await FakeSourceKitD . getOrCreate ( try AbsolutePath ( validating: " /a " ) , in: registry)
45
46
46
47
await assertTrue ( a === FakeSourceKitD . getOrCreate ( try AbsolutePath ( validating: " /a " ) , in: registry) )
@@ -58,19 +59,18 @@ final class SourceKitDRegistryTests: XCTestCase {
58
59
}
59
60
}
60
61
61
- private var nextToken = 0
62
+ private nonisolated ( unsafe ) var nextToken = AtomicUInt32 ( initialValue : 0 )
62
63
63
64
final class FakeSourceKitD : SourceKitD {
64
- let token : Int
65
+ let token : UInt32
65
66
var api : sourcekitd_api_functions_t { fatalError ( ) }
66
67
var keys : sourcekitd_api_keys { fatalError ( ) }
67
68
var requests : sourcekitd_api_requests { fatalError ( ) }
68
69
var values : sourcekitd_api_values { fatalError ( ) }
69
70
func addNotificationHandler( _ handler: SKDNotificationHandler ) { fatalError ( ) }
70
71
func removeNotificationHandler( _ handler: SKDNotificationHandler ) { fatalError ( ) }
71
72
private init ( ) {
72
- token = nextToken
73
- nextToken += 1
73
+ token = nextToken. fetchAndIncrement ( )
74
74
}
75
75
76
76
static func getOrCreate( _ path: AbsolutePath , in registry: SourceKitDRegistry ) async -> SourceKitD {
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ final class SourceKitDTests: XCTestCase {
32
32
let keys = sourcekitd. keys
33
33
let path = DocumentURI . for ( . swift) . pseudoPath
34
34
35
- let isExpectedNotification = { ( response: SKDResponse ) -> Bool in
35
+ let isExpectedNotification = { @ Sendable ( response: SKDResponse ) -> Bool in
36
36
if let notification: sourcekitd_api_uid_t = response. value ? [ keys. notification] ,
37
37
let name: String = response. value ? [ keys. name]
38
38
{
@@ -95,10 +95,10 @@ final class SourceKitDTests: XCTestCase {
95
95
}
96
96
}
97
97
98
- private class ClosureNotificationHandler : SKDNotificationHandler {
99
- let f : ( SKDResponse ) -> Void
98
+ private final class ClosureNotificationHandler : SKDNotificationHandler {
99
+ let f : @ Sendable ( SKDResponse ) -> Void
100
100
101
- init ( _ f: @escaping ( SKDResponse ) -> Void ) {
101
+ init ( _ f: @Sendable @ escaping ( SKDResponse ) -> Void ) {
102
102
self . f = f
103
103
}
104
104
You can’t perform that action at this time.
0 commit comments