Skip to content

Commit 524037f

Browse files
committed
Remove more blocking_sync calls
This just removes a bunch of calls that can trivially become async.
1 parent bb91a15 commit 524037f

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

Sources/SWBBuildSystem/BuildOperation.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,7 @@ private class InProcessCommand: SWBLLBuild.ExternalCommand, SWBLLBuild.ExternalD
12541254
// Get the current output delegate from the adaptor.
12551255
//
12561256
// FIXME: This should never fail (since we are executing), but we have seen a crash here with that assumption. For now we are defensive until the source can be tracked down: <rdar://problem/31670274> Diagnose unexpected missing output delegate from: <rdar://problem/31669245> Crash in InProcessCommand.execute()
1257-
guard let outputDelegate = adaptor.getActiveOutputDelegate(command) else {
1257+
guard let outputDelegate = await adaptor.getActiveOutputDelegate(command) else {
12581258
return .failed
12591259
}
12601260

@@ -1604,9 +1604,9 @@ internal final class OperationSystemAdaptor: SWBLLBuild.BuildSystemDelegate, Act
16041604
/// Get the active output delegate for an executing command.
16051605
///
16061606
/// - returns: The active delegate, or nil if not found.
1607-
func getActiveOutputDelegate(_ command: Command) -> (any TaskOutputDelegate)? {
1607+
func getActiveOutputDelegate(_ command: Command) async -> (any TaskOutputDelegate)? {
16081608
// FIXME: This is a very bad idea, doing a sync against the response queue is introducing artificial latency when an in-process command needs to wait for the response queue to flush. However, we also can't simply move to a decoupled lock, because we don't want the command to start reporting output before it has been fully reported as having started. We need to move in-process task to another model.
1609-
return queue.blocking_sync {
1609+
return await queue.sync {
16101610
self.commandOutputDelegates[command]
16111611
}
16121612
}

Sources/SWBCore/LibSwiftDriver/LibSwiftDriver.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,9 @@ public final class SwiftModuleDependencyGraph: SwiftGlobalExplicitDependencyGrap
238238
return fileDependencies
239239
}
240240

241-
public func queryTransitiveDependencyModuleNames(for key: String) throws -> [String] {
242-
let graph = try registryQueue.blocking_sync {
243-
guard let driver = registry[key] else {
241+
public func queryTransitiveDependencyModuleNames(for key: String) async throws -> [String] {
242+
let graph = try await registryQueue.sync {
243+
guard let driver = self.registry[key] else {
244244
throw StubError.error("Unable to find jobs for key \(key). Be sure to plan the build ahead of fetching results.")
245245
}
246246
return driver.intermoduleDependencyGraph

Sources/SWBTaskExecution/TaskActions/SwiftDriverTaskAction.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ final public class SwiftDriverTaskAction: TaskAction, BuildValueValidatingTaskAc
9494
}
9595

9696
if driverPayload.reportRequiredTargetDependencies != .no && driverPayload.explicitModulesEnabled, let target = task.forTarget {
97-
let dependencyModuleNames = try dependencyGraph.queryTransitiveDependencyModuleNames(for: driverPayload.uniqueID)
97+
let dependencyModuleNames = try await dependencyGraph.queryTransitiveDependencyModuleNames(for: driverPayload.uniqueID)
9898
for dependencyModuleName in dependencyModuleNames {
9999
if let targetDependencies = dynamicExecutionDelegate.operationContext.definingTargetsByModuleName[dependencyModuleName] {
100100
for targetDependency in targetDependencies {

Sources/SWBUtil/SWBDispatch.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,20 @@ public final class SWBQueue: Sendable {
295295
}
296296
}
297297

298+
/// Submits a block object for execution and returns after that block finishes executing.
299+
/// - note: This implementation won't block the calling thread, unlike the synchronous overload of ``sync()``.
300+
public func sync<T>(qos: SWBQoS = .unspecified, flags: DispatchWorkItemFlags = [], execute block: @Sendable @escaping () throws -> T) async throws -> T {
301+
try await withCheckedThrowingContinuation { continuation in
302+
queue.async(qos: qos.dispatchQoS, flags: flags.dispatchFlags) {
303+
do {
304+
continuation.resume(returning: try block())
305+
} catch {
306+
continuation.resume(throwing: error)
307+
}
308+
}
309+
}
310+
}
311+
298312
public func async(group: SWBDispatchGroup? = nil, qos: SWBQoS = .unspecified, execute body: @escaping @Sendable () -> Void) {
299313
return queue.async(group: group?.group, qos: qos.dispatchQoS, execute: body)
300314
}

0 commit comments

Comments
 (0)