20
20
@interface SSYOperationQueue ()
21
21
22
22
@property (retain ) id noAppNapActivity ;
23
- @property (assign ) BOOL didTearDown;
24
23
25
24
@end
26
25
@@ -129,17 +128,9 @@ - (id)init {
129
128
return self ;
130
129
}
131
130
132
- - (void )tearDown {
133
- if (!self.didTearDown ) {
134
- [self removeObserver: self
135
- forKeyPath: @" operations" ];
136
- self.didTearDown = YES ;
137
- }
138
- }
139
-
140
131
- (void )dealloc {
141
- /* This should have already been done, but in case not… */
142
- [ self tearDown ];
132
+ [ self removeObserver: self
133
+ forKeyPath: @" operations " ];
143
134
144
135
[m_error release ] ;
145
136
[m_scriptCommand release ] ;
@@ -177,19 +168,19 @@ + (BOOL)operationGroupsSameInfo:(NSDictionary*)info
177
168
return NO ;
178
169
}
179
170
180
- - (void )postQueueDidBeginWorkForObject : ( id ) object {
171
+ - (void )postQueueDidBeginWork {
181
172
NSNotification * notification = [NSNotification notificationWithName: SSYOperationQueueDidBeginWorkNotification
182
- object: object ] ;
173
+ object: self ] ;
183
174
[[NSNotificationQueue defaultQueue ] enqueueNotification: notification
184
175
postingStyle: NSPostNow
185
176
coalesceMask: (NSNotificationCoalescingOnName|NSNotificationCoalescingOnSender)
186
177
forModes: nil ] ;
187
178
// See header doc regarding notifications for posting style explanation
188
179
}
189
180
190
- - (void )postQueueDidEndWorkForObject : ( id ) object {
181
+ - (void )postQueueDidEndWork {
191
182
NSNotification * notification = [NSNotification notificationWithName: SSYOperationQueueDidEndWorkNotification
192
- object: object ] ;
183
+ object: self ] ;
193
184
[[NSNotificationQueue defaultQueue ] enqueueNotification: notification
194
185
postingStyle: NSPostWhenIdle
195
186
coalesceMask: (NSNotificationCoalescingOnName|NSNotificationCoalescingOnSender)
@@ -238,15 +229,6 @@ - (void)observeValueForKeyPath:(NSString*)keyPath
238
229
[scriptCommand resumeExecutionWithResult: [self scriptResult ]] ;
239
230
[self setScriptCommand: nil ] ;
240
231
241
- NSOperation <SSYOwnee> * operation = [oldOperations objectAtIndex: 0 ] ;
242
- id owner ;
243
- if ([operation respondsToSelector: @selector (owner )]) {
244
- owner = [operation owner ] ;
245
- }
246
- else {
247
- owner = self ;
248
- }
249
-
250
232
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1090
251
233
// Being built with macOS 10.9 or later SDK
252
234
id activity = [self noAppNapActivity ] ;
@@ -267,8 +249,8 @@ - (void)observeValueForKeyPath:(NSString*)keyPath
267
249
// introduction, not in -operations) that KVO notifications
268
250
// for -operations can occur on any thread. However, our
269
251
// notifications are expected to be sent on the main thread…
270
- [self performSelectorOnMainThread: @selector (postQueueDidEndWorkForObject: )
271
- withObject: owner
252
+ [self performSelectorOnMainThread: @selector (postQueueDidEndWork )
253
+ withObject: nil
272
254
waitUntilDone: NO ] ; // as in NO deadlocks :)
273
255
274
256
[self setSkipOperationsExceptGroups: nil ] ;
@@ -279,7 +261,7 @@ - (void)observeValueForKeyPath:(NSString*)keyPath
279
261
// array, the above condition *must* mean that the *count*
280
262
// has just changed from 0 to some positive number.
281
263
// Actually, even though I add operations one at a time in
282
- // queueGroup::::::::: , I see that I get one notification
264
+ // queueGroup:::::::, I see that I get one notification
283
265
// when the count jumps from 0 to, say, 5. Apparently,
284
266
// KVO notifications are coalesced.
285
267
@@ -310,21 +292,12 @@ - (void)observeValueForKeyPath:(NSString*)keyPath
310
292
}
311
293
#endif
312
294
313
- NSOperation <SSYOwnee> * operation = [[self operations ] objectAtIndex: 0 ] ;
314
- id owner ;
315
- if ([operation respondsToSelector: @selector (owner )]) {
316
- owner = [operation owner ] ;
317
- }
318
- else {
319
- owner = self ;
320
- }
321
-
322
295
// It is stated in the documentation of NSOperationQueue (in the
323
296
// introduction, not in -operations) that KVO notifications
324
297
// for -operations can occur on any thread. However, our
325
298
// notifications are expected to be sent on the main thread…
326
- [self performSelectorOnMainThread: @selector (postQueueDidBeginWorkForObject: )
327
- withObject: owner
299
+ [self performSelectorOnMainThread: @selector (postQueueDidBeginWork )
300
+ withObject: nil
328
301
waitUntilDone: NO ] ; // as in NO deadlocks :)
329
302
}
330
303
}
@@ -333,7 +306,7 @@ - (void)observeValueForKeyPath:(NSString*)keyPath
333
306
- (void )doDone : (NSDictionary *)doneInfo {
334
307
NSError * error = [self error ] ;
335
308
336
- // Note that if the doneTarget provided to queueGroup:::::::::
309
+ // Note that if the doneTarget provided to queueGroup::::::::
337
310
// was nil or the doneSelector was NULL, doneThread will be nil
338
311
// and the following statements will return nil.
339
312
NSThread * doneThread = [doneInfo objectForKey: constKeySSYOperationQueueDoneThread] ;
@@ -359,7 +332,6 @@ - (void)queueGroup:(NSString*)group
359
332
selectorNames : (NSArray *)selectorNames
360
333
info : (NSMutableDictionary *)info
361
334
block : (BOOL )block
362
- owner : (id )owner
363
335
doneThread : (NSThread *)doneThread
364
336
doneTarget : (id )doneTarget
365
337
doneSelector : (SEL )doneSelector
@@ -403,7 +375,6 @@ - (void)queueGroup:(NSString*)group
403
375
&selectorNames,
404
376
&originalInfo,
405
377
&block,
406
- &owner,
407
378
&doneThread,
408
379
&doneTarget,
409
380
&doneSelector,
@@ -413,24 +384,17 @@ - (void)queueGroup:(NSString*)group
413
384
[info setObject: group
414
385
forKey: constKeySSYOperationGroup] ;
415
386
416
- // Create an array of operations from the array of selector names
417
- NSMutableArray * operations = [[NSMutableArray alloc ] init ] ;
418
387
for (NSString * selectorName in selectorNames) {
419
388
SEL selector = NSSelectorFromString (selectorName) ;
420
389
SSYOperation* op = [[SSYOperation alloc ] initWithInfo: info
421
390
target: nil
422
391
selector: selector
423
- owner: owner
424
392
operationQueue: self
425
393
skipIfError: YES ] ;
426
- // Note that operation is double-retained. We'll release it in the next loop.
427
- [operations addObject: op] ;
428
394
[self addAtEndOperation: op] ;
429
395
[op release ] ;
430
396
}
431
-
432
- [operations release ] ;
433
-
397
+
434
398
// Create a final operation which will be the 'done' invocation
435
399
// and add it to the queue.
436
400
NSMutableDictionary * doneInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@@ -447,8 +411,7 @@ - (void)queueGroup:(NSString*)group
447
411
forKey: constKeySSYOperationQueueDoneTarget] ;
448
412
[doneInfo setObject: NSStringFromSelector (doneSelector)
449
413
forKey: constKeySSYOperationQueueDoneSelectorName] ;
450
- // Added in BookMacster 1.11, for no purpose other than
451
- // filling out -[SSYOperation description] …
414
+ // This is to fill out -[SSYOperation description] …
452
415
[doneInfo setObject: group
453
416
forKey: constKeySSYOperationGroup] ;
454
417
}
@@ -457,7 +420,6 @@ - (void)queueGroup:(NSString*)group
457
420
SSYOperation* op = [[SSYOperation alloc ] initWithInfo: doneInfo
458
421
target: self
459
422
selector: @selector (doDone: )
460
- owner: owner
461
423
operationQueue: self
462
424
skipIfError: NO ] ;
463
425
[self addAtEndOperation: op] ;
0 commit comments