Skip to content

Commit fda6d4e

Browse files
lilyballgribozavr
authored andcommitted
Add fast path for queue.async(flags: .barrier)
Fixes SR-2248.
1 parent 03415be commit fda6d4e

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

stdlib/public/SDK/Dispatch/Queue.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,15 @@ public extension DispatchQueue {
197197
flags: DispatchWorkItemFlags = [],
198198
execute work: @escaping @convention(block) () -> Void)
199199
{
200-
if group == nil && qos == .unspecified && flags.isEmpty {
200+
if group == nil && qos == .unspecified {
201201
// Fast-path route for the most common API usage
202-
__dispatch_async(self, work)
203-
return
202+
if flags.isEmpty {
203+
__dispatch_async(self, work)
204+
return
205+
} else if flags == .barrier {
206+
__dispatch_barrier_async(self, work)
207+
return
208+
}
204209
}
205210

206211
var block: @convention(block) () -> Void = work

0 commit comments

Comments
 (0)