ObjFW  Check-in [8658d1a22a]

Overview
Comment:Make it possible to invalidate OFTimers.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 8658d1a22a3d3de92f65a030c141f1f86720a3168cacb0a7d88579d007a27d38
User & Date: js on 2012-09-16 21:59:37
Other Links: manifest | tags
Context
2012-09-16
22:16
Make sure an autorelease pool is always in place. check-in: cc9601c228 user: js tags: trunk
21:59
Make it possible to invalidate OFTimers. check-in: 8658d1a22a user: js tags: trunk
15:43
OFStream: Use lowlevel as prefix instead of _. check-in: 61c1932caf user: js tags: trunk
Changes

Modified src/OFObject.m from [91d44503b0] to [2de861858b].

605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
					 object: object
					repeats: NO];

	objc_autoreleasePoolPop(pool);
}

- (void)performSelector: (SEL)selector
	     withObject: (id)object
	     withObject: (id)otherObject
	     afterDelay: (double)delay
{
	void *pool = objc_autoreleasePoolPush();

	[OFTimer scheduledTimerWithTimeInterval: delay
					 target: self
				       selector: selector
					 object: object
					 object: object
					repeats: NO];

	objc_autoreleasePoolPop(pool);
}

- (void)performSelector: (SEL)selector
	       onThread: (OFThread*)thread







|
|







|
|







605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
					 object: object
					repeats: NO];

	objc_autoreleasePoolPop(pool);
}

- (void)performSelector: (SEL)selector
	     withObject: (id)object1
	     withObject: (id)object2
	     afterDelay: (double)delay
{
	void *pool = objc_autoreleasePoolPush();

	[OFTimer scheduledTimerWithTimeInterval: delay
					 target: self
				       selector: selector
					 object: object1
					 object: object2
					repeats: NO];

	objc_autoreleasePoolPop(pool);
}

- (void)performSelector: (SEL)selector
	       onThread: (OFThread*)thread
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
							   repeats: NO]];

	objc_autoreleasePoolPop(pool);
}

- (void)performSelector: (SEL)selector
	       onThread: (OFThread*)thread
	     withObject: (id)object
	     withObject: (id)otherObject
	     afterDelay: (double)delay
{
	void *pool = objc_autoreleasePoolPush();

	[[thread runLoop] addTimer: [OFTimer timerWithTimeInterval: delay
							    target: self
							  selector: selector
							    object: object
							    object: object
							   repeats: NO]];

	objc_autoreleasePoolPop(pool);
}

- (const char*)typeEncodingForSelector: (SEL)selector
{







|
|







|
|







653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
							   repeats: NO]];

	objc_autoreleasePoolPop(pool);
}

- (void)performSelector: (SEL)selector
	       onThread: (OFThread*)thread
	     withObject: (id)object1
	     withObject: (id)object2
	     afterDelay: (double)delay
{
	void *pool = objc_autoreleasePoolPush();

	[[thread runLoop] addTimer: [OFTimer timerWithTimeInterval: delay
							    target: self
							  selector: selector
							    object: object1
							    object: object2
							   repeats: NO]];

	objc_autoreleasePoolPop(pool);
}

- (const char*)typeEncodingForSelector: (SEL)selector
{

Modified src/OFRunLoop.m from [021a7791a3] to [cf11bcd288].

318
319
320
321
322
323
324

325
326
327
328
329
330
331
332
				    [[listObject->object retain] autorelease];

				[timersQueue removeListObject: listObject];
			} else
				timer = nil;
		}


		[timer fire];

		@synchronized (timersQueue) {
			nextTimer = [[timersQueue firstObject] fireDate];
		}

		/* Watch for stream events until the next timer is due */
		if (nextTimer != nil) {







>
|







318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
				    [[listObject->object retain] autorelease];

				[timersQueue removeListObject: listObject];
			} else
				timer = nil;
		}

		if ([timer isValid])
			[timer fire];

		@synchronized (timersQueue) {
			nextTimer = [[timersQueue firstObject] fireDate];
		}

		/* Watch for stream events until the next timer is due */
		if (nextTimer != nil) {

Modified src/OFTimer.h from [e58cca5bff] to [ff1fcecae5].

32
33
34
35
36
37
38

39
40
41
42
43
44
45
	id target, object1, object2;
	SEL selector;
	uint8_t arguments;
	BOOL repeats;
#ifdef OF_HAVE_BLOCKS
	of_timer_block_t block;
#endif

}

/**
 * \brief Creates and schedules a new timer with the specified time interval.
 *
 * \param interval The time interval after which the timer should be executed
 *		   when fired







>







32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
	id target, object1, object2;
	SEL selector;
	uint8_t arguments;
	BOOL repeats;
#ifdef OF_HAVE_BLOCKS
	of_timer_block_t block;
#endif
	BOOL isValid;
}

/**
 * \brief Creates and schedules a new timer with the specified time interval.
 *
 * \param interval The time interval after which the timer should be executed
 *		   when fired
258
259
260
261
262
263
264





















265

/**
 * \brief Returns the next date at which the timer will fire.
 *
 * \return The next date at which the timer will fire
 */
- (OFDate*)fireDate;





















@end







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

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

/**
 * \brief Returns the next date at which the timer will fire.
 *
 * \return The next date at which the timer will fire
 */
- (OFDate*)fireDate;

/**
 * \brief Invalidates the timer, preventing it from firing.
 */
- (void)invalidate;

/**
 * \brief Returns whether the timer is valid.
 *
 * \return Whether the timer is valid
 */
- (BOOL)isValid;

/**
 * \brief Returns the time interval in which the timer will repeat, if it is a
 *	  repeating timer.
 *
 * \return The time interval in which the timer will repeat, if it is a
 *	   repeating timer
 */
- (double)timeInterval;
@end

Modified src/OFTimer.m from [83b4c66f44] to [925c86fe94].

214
215
216
217
218
219
220

221
222
223
224
225
226
227
		interval = interval_;
		target = [target_ retain];
		selector = selector_;
		object1 = [object1_ retain];
		object2 = [object2_ retain];
		arguments = arguments_;
		repeats = repeats_;

	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}







>







214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
		interval = interval_;
		target = [target_ retain];
		selector = selector_;
		object1 = [object1_ retain];
		object2 = [object2_ retain];
		arguments = arguments_;
		repeats = repeats_;
		isValid = YES;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
356
357
358
359
360
361
362
363

364
365
366
367
368
369















370
	if (repeats) {
		OFDate *old = fireDate;
		fireDate = [[OFDate alloc]
		    initWithTimeIntervalSinceNow: interval];
		[old release];

		[[OFRunLoop currentRunLoop] addTimer: self];
	}

}

- (OFDate*)fireDate
{
	return [[fireDate retain] autorelease];
}















@end







|
>






>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
	if (repeats) {
		OFDate *old = fireDate;
		fireDate = [[OFDate alloc]
		    initWithTimeIntervalSinceNow: interval];
		[old release];

		[[OFRunLoop currentRunLoop] addTimer: self];
	} else
		isValid = NO;
}

- (OFDate*)fireDate
{
	return [[fireDate retain] autorelease];
}

- (double)timeInterval
{
	return interval;
}

- (void)invalidate
{
	isValid = NO;
}

- (BOOL)isValid
{
	return isValid;
}
@end