@@ -34,6 +34,8 @@ import class TSCBasic.Process
34
34
import class TSCUtility. PercentProgressAnimation
35
35
#endif
36
36
37
+ import Synchronization
38
+
37
39
/// When diagnosis is started, a progress bar displayed on the terminal that shows how far the diagnose command has
38
40
/// progressed.
39
41
/// Can't be a member of `DiagnoseCommand` because then `DiagnoseCommand` is no longer codable, which it needs to be
@@ -233,8 +235,8 @@ package struct DiagnoseCommand: AsyncParsableCommand {
233
235
throw GenericError ( " Failed to create log.txt " )
234
236
}
235
237
let fileHandle = try FileHandle ( forWritingTo: outputFileUrl)
236
- let bytesCollected = AtomicInt32 ( initialValue : 0 )
237
- let processExited = AtomicBool ( initialValue : false )
238
+ let bytesCollected : Atomic < Int > = Atomic ( 0 )
239
+ let processExited : Atomic < Bool > = Atomic ( false )
238
240
// 50 MB is an average log size collected by sourcekit-lsp diagnose.
239
241
// It's a good proxy to show some progress indication for the majority of the time.
240
242
let expectedLogSize = 50_000_000
@@ -250,16 +252,16 @@ package struct DiagnoseCommand: AsyncParsableCommand {
250
252
outputRedirection: . stream(
251
253
stdout: { @Sendable bytes in
252
254
try ? fileHandle. write ( contentsOf: bytes)
253
- bytesCollected . value += Int32 ( bytes. count)
254
- var progress = Double ( bytesCollected . value ) / Double( expectedLogSize)
255
+ let count = bytesCollected . add ( bytes. count, ordering : . sequentiallyConsistent ) . newValue
256
+ var progress = Double ( count ) / Double( expectedLogSize)
255
257
if progress > 1 {
256
258
// The log is larger than we expected. Halt at 100%
257
259
progress = 1
258
260
}
259
261
Task ( priority: . high) {
260
262
// We have launched an async task to call `reportProgress`, which means that the process might have exited
261
263
// before we execute this task. To avoid overriding a more recent progress, add a guard.
262
- if !processExited. value {
264
+ if !processExited. load ( ordering : . sequentiallyConsistent ) {
263
265
await reportProgress ( . collectingLogMessages( progress: progress) , message: " Collecting log messages " )
264
266
}
265
267
}
@@ -269,7 +271,7 @@ package struct DiagnoseCommand: AsyncParsableCommand {
269
271
)
270
272
try process. launch ( )
271
273
try await process. waitUntilExit ( )
272
- processExited. value = true
274
+ processExited. store ( true , ordering : . sequentiallyConsistent )
273
275
#endif
274
276
}
275
277
0 commit comments