Skip to content

Commit

Permalink
[Issue Alamofire#175] Refining dispatch-based synchronized access to …
Browse files Browse the repository at this point in the history
…subdelegates
  • Loading branch information
mattt committed Oct 20, 2014
1 parent 959fb5e commit 923c009
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Source/Alamofire.swift
Original file line number Diff line number Diff line change
Expand Up @@ -337,14 +337,19 @@ public class Manager {

class SessionDelegate: NSObject, NSURLSessionDelegate, NSURLSessionTaskDelegate, NSURLSessionDataDelegate, NSURLSessionDownloadDelegate {
private var subdelegates: [Int: Request.TaskDelegate]
private let subdelegateQueue = dispatch_queue_create(nil, DISPATCH_QUEUE_SERIAL)
private let subdelegateQueue = dispatch_queue_create(nil, DISPATCH_QUEUE_CONCURRENT)
private subscript(task: NSURLSessionTask) -> Request.TaskDelegate? {
get {
return subdelegates[task.taskIdentifier]
var subdelegate: Request.TaskDelegate?
dispatch_sync(subdelegateQueue) {
subdelegate = self.subdelegates[task.taskIdentifier]
}

return subdelegate
}

set {
dispatch_sync(subdelegateQueue) {
dispatch_barrier_async(subdelegateQueue) {
self.subdelegates[task.taskIdentifier] = newValue
}
}
Expand Down

0 comments on commit 923c009

Please sign in to comment.