Skip to content

Commit

Permalink
Merge pull request onevcat#790 from onevcat/fix/thread-racing
Browse files Browse the repository at this point in the history
Resolve a reading racing condition
  • Loading branch information
onevcat authored Oct 17, 2017
2 parents 5c74496 + 51d9b22 commit 3083b86
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions Sources/ImageDownloader.swift
Original file line number Diff line number Diff line change
@@ -412,13 +412,6 @@ extension ImageDownloader {
}
}
}

func clean(for url: URL) {
barrierQueue.sync(flags: .barrier) {
fetchLoads.removeValue(forKey: url)
return
}
}
}

// MARK: - NSURLSessionDataDelegate
@@ -510,11 +503,12 @@ class ImageDownloaderSessionHandler: NSObject, URLSessionDataDelegate, Authentic
guard let downloader = downloadHolder else {
return
}

downloader.clean(for: url)

if downloader.fetchLoads.isEmpty {
downloadHolder = nil

downloader.barrierQueue.sync(flags: .barrier) {
downloader.fetchLoads.removeValue(forKey: url)
if downloader.fetchLoads.isEmpty {
downloadHolder = nil
}
}
}

0 comments on commit 3083b86

Please sign in to comment.