Authored by DreamPiggy

Follow Apple's doc, add NSOperation only after all configuration done.

@@ -235,7 +235,6 @@ @@ -235,7 +235,6 @@
235 operation.queuePriority = NSOperationQueuePriorityLow; 235 operation.queuePriority = NSOperationQueuePriorityLow;
236 } 236 }
237 237
238 - [sself.downloadQueue addOperation:operation];  
239 if (sself.executionOrder == SDWebImageDownloaderLIFOExecutionOrder) { 238 if (sself.executionOrder == SDWebImageDownloaderLIFOExecutionOrder) {
240 // Emulate LIFO execution order by systematically adding new operations as last operation's dependency 239 // Emulate LIFO execution order by systematically adding new operations as last operation's dependency
241 [sself.lastAddedOperation addDependency:operation]; 240 [sself.lastAddedOperation addDependency:operation];
@@ -289,6 +288,9 @@ @@ -289,6 +288,9 @@
289 UNLOCK(sself.operationsLock); 288 UNLOCK(sself.operationsLock);
290 }; 289 };
291 [self.URLOperations setObject:operation forKey:url]; 290 [self.URLOperations setObject:operation forKey:url];
  291 + // Add operation to operation queue only after all configuration done according to Apple's doc.
  292 + // `addOperation:` does not synchronously execute the `operation.completionBlock` so this will not cause deadlock.
  293 + [self.downloadQueue addOperation:operation];
292 } 294 }
293 UNLOCK(self.operationsLock); 295 UNLOCK(self.operationsLock);
294 296