@@ -34,6 +34,8 @@ import class TSCBasic.Process
3434import class TSCUtility. PercentProgressAnimation
3535#endif
3636
37+ import Synchronization
38+
3739/// When diagnosis is started, a progress bar displayed on the terminal that shows how far the diagnose command has
3840/// progressed.
3941/// 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 {
233235 throw GenericError ( " Failed to create log.txt " )
234236 }
235237 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 )
238240 // 50 MB is an average log size collected by sourcekit-lsp diagnose.
239241 // It's a good proxy to show some progress indication for the majority of the time.
240242 let expectedLogSize = 50_000_000
@@ -250,16 +252,16 @@ package struct DiagnoseCommand: AsyncParsableCommand {
250252 outputRedirection: . stream(
251253 stdout: { @Sendable bytes in
252254 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)
255257 if progress > 1 {
256258 // The log is larger than we expected. Halt at 100%
257259 progress = 1
258260 }
259261 Task ( priority: . high) {
260262 // We have launched an async task to call `reportProgress`, which means that the process might have exited
261263 // 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 ) {
263265 await reportProgress ( . collectingLogMessages( progress: progress) , message: " Collecting log messages " )
264266 }
265267 }
@@ -269,7 +271,7 @@ package struct DiagnoseCommand: AsyncParsableCommand {
269271 )
270272 try process. launch ( )
271273 try await process. waitUntilExit ( )
272- processExited. value = true
274+ processExited. store ( true , ordering : . sequentiallyConsistent )
273275 #endif
274276 }
275277
0 commit comments