Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Sources/Concurrency/AutoReleasingSemaphore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class AutoReleasingSemaphore {
/// in dispatch_semaphore_wait(_:_:).
/// - returns: This function returns non-zero if a thread is woken.
/// Otherwise, zero is returned.
@discardableResult
public func signal() -> Int {
let newValue = waitingCount.decrementAndGet()
if newValue < 0 {
Expand Down Expand Up @@ -65,6 +66,7 @@ public class AutoReleasingSemaphore {
/// - parameter timeout: The amount of time in seconds to wait
/// before returning with failure.
/// - returns: The waiting result.
@discardableResult
public func wait(timeout: TimeInterval) -> DispatchTimeoutResult {
waitingCount.incrementAndGet()
return semaphore.wait(timeout: DispatchTime.now() + timeout)
Expand Down
4 changes: 2 additions & 2 deletions Sources/Concurrency/Executor/ConcurrentSequenceExecutor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class ConcurrentSequenceExecutor: SequenceExecutor {
public init(name: String, qos: DispatchQoS = .userInitiated, shouldTrackTaskId: Bool = false, maxConcurrentTasks: Int? = nil) {
taskQueue = DispatchQueue(label: "Executor.taskQueue-\(name)", qos: qos, attributes: .concurrent)
if let maxConcurrentTasks = maxConcurrentTasks {
taskSemaphore = DispatchSemaphore(value: maxConcurrentTasks)
taskSemaphore = AutoReleasingSemaphore(value: maxConcurrentTasks)
} else {
taskSemaphore = nil
}
Expand All @@ -66,7 +66,7 @@ public class ConcurrentSequenceExecutor: SequenceExecutor {
// MARK: - Private

private let taskQueue: DispatchQueue
private let taskSemaphore: DispatchSemaphore?
private let taskSemaphore: AutoReleasingSemaphore?
private let shouldTrackTaskId: Bool

private func execute<SequenceResultType>(_ task: Task, with sequenceHandle: SynchronizedSequenceExecutionHandle<SequenceResultType>, _ execution: @escaping (Task, Any) -> SequenceExecution<SequenceResultType>) {
Expand Down