︙ | | |
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
-
+
|
#import "autorelease.h"
#import "macros.h"
@implementation OFTimer
+ (instancetype)scheduledTimerWithTimeInterval: (double)interval
target: (id)target
selector: (SEL)selector
repeats: (BOOL)repeats
repeats: (bool)repeats
{
void *pool = objc_autoreleasePoolPush();
OFDate *fireDate = [OFDate dateWithTimeIntervalSinceNow: interval];
id timer = [[[self alloc] initWithFireDate: fireDate
interval: interval
target: target
selector: selector
|
︙ | | |
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
-
+
|
return [timer autorelease];
}
+ (instancetype)scheduledTimerWithTimeInterval: (double)interval
target: (id)target
selector: (SEL)selector
object: (id)object
repeats: (BOOL)repeats
repeats: (bool)repeats
{
void *pool = objc_autoreleasePoolPush();
OFDate *fireDate = [OFDate dateWithTimeIntervalSinceNow: interval];
id timer = [[[self alloc] initWithFireDate: fireDate
interval: interval
target: target
selector: selector
|
︙ | | |
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
-
+
|
}
+ (instancetype)scheduledTimerWithTimeInterval: (double)interval
target: (id)target
selector: (SEL)selector
object: (id)object1
object: (id)object2
repeats: (BOOL)repeats
repeats: (bool)repeats
{
void *pool = objc_autoreleasePoolPush();
OFDate *fireDate = [OFDate dateWithTimeIntervalSinceNow: interval];
id timer = [[[self alloc] initWithFireDate: fireDate
interval: interval
target: target
selector: selector
|
︙ | | |
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
-
+
|
objc_autoreleasePoolPop(pool);
return [timer autorelease];
}
#ifdef OF_HAVE_BLOCKS
+ (instancetype)scheduledTimerWithTimeInterval: (double)interval
repeats: (BOOL)repeats
repeats: (bool)repeats
block: (of_timer_block_t)block
{
void *pool = objc_autoreleasePoolPush();
OFDate *fireDate = [OFDate dateWithTimeIntervalSinceNow: interval];
id timer = [[[self alloc] initWithFireDate: fireDate
interval: interval
repeats: repeats
|
︙ | | |
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
-
+
-
+
|
return [timer autorelease];
}
#endif
+ (instancetype)timerWithTimeInterval: (double)interval
target: (id)target
selector: (SEL)selector
repeats: (BOOL)repeats
repeats: (bool)repeats
{
void *pool = objc_autoreleasePoolPush();
OFDate *fireDate = [OFDate dateWithTimeIntervalSinceNow: interval];
id timer = [[[self alloc] initWithFireDate: fireDate
interval: interval
target: target
selector: selector
repeats: repeats] autorelease];
[timer retain];
objc_autoreleasePoolPop(pool);
return [timer autorelease];
}
+ (instancetype)timerWithTimeInterval: (double)interval
target: (id)target
selector: (SEL)selector
object: (id)object
repeats: (BOOL)repeats
repeats: (bool)repeats
{
void *pool = objc_autoreleasePoolPush();
OFDate *fireDate = [OFDate dateWithTimeIntervalSinceNow: interval];
id timer = [[[self alloc] initWithFireDate: fireDate
interval: interval
target: target
selector: selector
|
︙ | | |
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
-
+
-
+
|
}
+ (instancetype)timerWithTimeInterval: (double)interval
target: (id)target
selector: (SEL)selector
object: (id)object1
object: (id)object2
repeats: (BOOL)repeats
repeats: (bool)repeats
{
void *pool = objc_autoreleasePoolPush();
OFDate *fireDate = [OFDate dateWithTimeIntervalSinceNow: interval];
id timer = [[[self alloc] initWithFireDate: fireDate
interval: interval
target: target
selector: selector
object: object1
object: object2
repeats: repeats] autorelease];
[timer retain];
objc_autoreleasePoolPop(pool);
return [timer autorelease];
}
#ifdef OF_HAVE_BLOCKS
+ (instancetype)timerWithTimeInterval: (double)interval
repeats: (BOOL)repeats
repeats: (bool)repeats
block: (of_timer_block_t)block
{
void *pool = objc_autoreleasePoolPush();
OFDate *fireDate = [OFDate dateWithTimeIntervalSinceNow: interval];
id timer = [[[self alloc] initWithFireDate: fireDate
interval: interval
repeats: repeats
|
︙ | | |
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
|
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
|
-
+
-
+
-
+
-
+
-
+
-
+
-
+
|
- OF_initWithFireDate: (OFDate*)fireDate
interval: (double)interval
target: (id)target
selector: (SEL)selector
object: (id)object1
object: (id)object2
arguments: (uint8_t)arguments
repeats: (BOOL)repeats
repeats: (bool)repeats
{
self = [super init];
@try {
_fireDate = [fireDate retain];
_interval = interval;
_target = [target retain];
_selector = selector;
_object1 = [object1 retain];
_object2 = [object2 retain];
_arguments = arguments;
_repeats = repeats;
_valid = YES;
_valid = true;
#ifdef OF_HAVE_THREADS
_condition = [[OFCondition alloc] init];
#endif
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- initWithFireDate: (OFDate*)fireDate
interval: (double)interval
target: (id)target
selector: (SEL)selector
repeats: (BOOL)repeats
repeats: (bool)repeats
{
return [self OF_initWithFireDate: fireDate
interval: interval
target: target
selector: selector
object: nil
object: nil
arguments: 0
repeats: repeats];
}
- initWithFireDate: (OFDate*)fireDate
interval: (double)interval
target: (id)target
selector: (SEL)selector
object: (id)object
repeats: (BOOL)repeats
repeats: (bool)repeats
{
return [self OF_initWithFireDate: fireDate
interval: interval
target: target
selector: selector
object: object
object: nil
arguments: 1
repeats: repeats];
}
- initWithFireDate: (OFDate*)fireDate
interval: (double)interval
target: (id)target
selector: (SEL)selector
object: (id)object1
object: (id)object2
repeats: (BOOL)repeats
repeats: (bool)repeats
{
return [self OF_initWithFireDate: fireDate
interval: interval
target: target
selector: selector
object: object1
object: object2
arguments: 2
repeats: repeats];
}
#ifdef OF_HAVE_BLOCKS
- initWithFireDate: (OFDate*)fireDate
interval: (double)interval
repeats: (BOOL)repeats
repeats: (bool)repeats
block: (of_timer_block_t)block
{
self = [super init];
@try {
_fireDate = [fireDate retain];
_interval = interval;
_repeats = repeats;
_block = [block copy];
_valid = YES;
_valid = true;
# ifdef OF_HAVE_THREADS
_condition = [[OFCondition alloc] init];
# endif
} @catch (id e) {
[self release];
@throw e;
}
|
︙ | | |
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
|
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
|
-
+
-
+
-
+
-
+
-
+
-
+
-
+
|
#ifdef OF_HAVE_BLOCKS
}
#endif
#ifdef OF_HAVE_THREADS
[_condition lock];
@try {
_done = YES;
_done = true;
[_condition signal];
} @finally {
[_condition unlock];
}
#endif
if (_repeats && _valid) {
OFDate *old = _fireDate;
_fireDate = [[OFDate alloc]
initWithTimeIntervalSinceNow: _interval];
[old release];
[[OFRunLoop currentRunLoop] addTimer: self];
} else
[self invalidate];
}
- (OFDate*)fireDate
{
OF_GETTER(_fireDate, YES)
OF_GETTER(_fireDate, true)
}
- (void)setFireDate: (OFDate*)fireDate
{
[self retain];
@try {
@synchronized (self) {
[_inRunLoop OF_removeTimer: self];
OF_SETTER(_fireDate, fireDate, YES, 0)
OF_SETTER(_fireDate, fireDate, true, 0)
[_inRunLoop addTimer: self];
}
} @finally {
[self release];
}
}
- (double)timeInterval
{
return _interval;
}
- (void)invalidate
{
_valid = NO;
_valid = false;
[_target release];
_target = nil;
}
- (BOOL)isValid
- (bool)isValid
{
return _valid;
}
#ifdef OF_HAVE_THREADS
- (void)waitUntilDone
{
[_condition lock];
@try {
if (_done) {
_done = NO;
_done = false;
return;
}
[_condition wait];
} @finally {
[_condition unlock];
}
}
#endif
- (void)OF_setInRunLoop: (OFRunLoop*)inRunLoop
{
OF_SETTER(_inRunLoop, inRunLoop, YES, 0)
OF_SETTER(_inRunLoop, inRunLoop, true, 0)
}
@end
|