File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change 88 See http://swift.org/CONTRIBUTORS.txt for Swift project authors
99*/
1010
11+ import Dispatch
12+
1113/// A type which can be used as a diagnostic parameter.
1214public protocol DiagnosticParameter {
1315
@@ -250,18 +252,28 @@ public protocol DiagnosticsScope {
250252}
251253
252254public class DiagnosticsEngine : CustomStringConvertible {
255+
256+ /// Queue to protect concurrent mutations to the diagnositcs engine.
257+ private let queue = DispatchQueue ( label: " \( DiagnosticsEngine . self) " )
258+
253259 /// The diagnostics produced by the engine.
254- public var diagnostics : [ Diagnostic ] = [ ]
260+ public var diagnostics : [ Diagnostic ] {
261+ return queue. sync { _diagnostics }
262+ }
263+ private var _diagnostics : [ Diagnostic ] = [ ]
255264
265+ /// Returns true if there is an error diagnostics in the engine.
256266 public var hasErrors : Bool {
257267 return diagnostics. contains ( where: { $0. behavior == . error } )
258268 }
259-
269+
260270 public init ( ) {
261271 }
262272
263273 public func emit( data: DiagnosticData , location: DiagnosticLocation ) {
264- diagnostics. append ( Diagnostic ( location: location, data: data) )
274+ queue. sync {
275+ _diagnostics. append ( Diagnostic ( location: location, data: data) )
276+ }
265277 }
266278
267279 /// Merges contents of given engine.
You can’t perform that action at this time.
0 commit comments