Skip to content

Commit 5d7fd3d

Browse files
authored
Replace TSC signal handler with Dispatch's (#990)
1 parent 30ade40 commit 5d7fd3d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Sources/swift-driver/main.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,20 @@ import Glibc
2020
#endif
2121
import TSCBasic
2222

23+
import Dispatch
24+
2325
#if os(Windows)
2426
import WinSDK
2527
#endif
2628

2729
import enum TSCUtility.Diagnostics
28-
import typealias TSCUtility.InterruptHandler
2930

30-
var intHandler: InterruptHandler?
31+
let interruptSignalSource = DispatchSource.makeSignalSource(signal: SIGINT)
3132
let diagnosticsEngine = DiagnosticsEngine(handlers: [Driver.stderrDiagnosticsHandler])
3233
var driverInterrupted = false
3334
func getExitCode(_ code: Int32) -> Int32 {
3435
if driverInterrupted {
35-
intHandler = nil
36+
interruptSignalSource.cancel()
3637
#if os(Windows)
3738
TerminateProcess(GetCurrentProcess(), UINT(0xC0000000 | UINT(2)))
3839
#else
@@ -46,7 +47,7 @@ func getExitCode(_ code: Int32) -> Int32 {
4647
do {
4748

4849
let processSet = ProcessSet()
49-
intHandler = try InterruptHandler {
50+
interruptSignalSource.setEventHandler {
5051
// Terminate running compiler jobs and let the driver exit gracefully, remembering
5152
// to return a corresponding exit code when done.
5253
processSet.terminate()

0 commit comments

Comments
 (0)