ObjFW  Diff

Differences From Artifact [7f6b2774f2]:

To Artifact [a47bada402]:

  • File src/OFTimer.m — part of check-in [48980f2297] at 2015-11-29 11:43:05 on branch trunk — Make properties a requirement and clean up code

    This increases the required GCC version from 4.0 to 4.6 (exception:
    Apple GCC, which already supports this with >= 4.0 starting with OS X
    10.5). Since even GCC 4.6 is really old by now, there is no point in
    still supporting something even older and making the code ugly because
    of that. While some hardware and OS support was dropped from GCC 4.6
    compared to GCC 4.0, there is nothing in there that would be an
    interesting target with the exception of BeOS maybe - but a port to BeOS
    can also be achieved using the Haiku support. The other dropped OSes are
    mostly old versions of OSes while newer ones are still being supported
    (and those newer versions of those OSes still support the same
    hardware). (user: js, size: 10494) [annotate] [blame] [check-ins using]


28
29
30
31
32
33
34



35
36
37
38
39
40
41
#ifdef OF_HAVE_THREADS
# import "OFCondition.h"
#endif

#import "OFInvalidArgumentException.h"

@implementation OFTimer



+ (instancetype)scheduledTimerWithTimeInterval: (of_time_interval_t)timeInterval
					target: (id)target
				      selector: (SEL)selector
				       repeats: (bool)repeats
{
	void *pool = objc_autoreleasePoolPush();
	OFDate *fireDate = [OFDate dateWithTimeIntervalSinceNow: timeInterval];







>
>
>







28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifdef OF_HAVE_THREADS
# import "OFCondition.h"
#endif

#import "OFInvalidArgumentException.h"

@implementation OFTimer
@synthesize timeInterval = _interval, isValid = _valid;
@synthesize OF_inRunLoop = _inRunLoop;

+ (instancetype)scheduledTimerWithTimeInterval: (of_time_interval_t)timeInterval
					target: (id)target
				      selector: (SEL)selector
				       repeats: (bool)repeats
{
	void *pool = objc_autoreleasePoolPush();
	OFDate *fireDate = [OFDate dateWithTimeIntervalSinceNow: timeInterval];
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
474
#endif

	objc_autoreleasePoolPop(pool);
}

- (OFDate*)fireDate
{
	OF_GETTER(_fireDate, true)
}

- (void)setFireDate: (OFDate*)fireDate
{
	[self retain];
	@try {
		@synchronized (self) {


			[_inRunLoop OF_removeTimer: self];

			OF_SETTER(_fireDate, fireDate, true, 0)



			[_inRunLoop addTimer: self];
		}
	} @finally {
		[self release];
	}
}

- (of_time_interval_t)timeInterval
{
	return _interval;
}

- (void)invalidate
{
	_valid = false;

	[_target release];
	[_object1 release];
	[_object2 release];
	_target = nil;
	_object1 = nil;
	_object2 = nil;
}

- (bool)isValid
{
	return _valid;
}

#ifdef OF_HAVE_THREADS
- (void)waitUntilDone
{
	[_condition lock];
	@try {
		if (_done) {
			_done = false;
			return;
		}

		[_condition wait];
	} @finally {
		[_condition unlock];
	}
}
#endif

- (void)OF_setInRunLoop: (OFRunLoop*)inRunLoop
{
	OF_SETTER(_inRunLoop, inRunLoop, true, 0)
}
@end







|







>
>


|
>
>








<
<
<
<
<












<
<
<
<
<
















<
<
<
<
<

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
#endif

	objc_autoreleasePoolPop(pool);
}

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

- (void)setFireDate: (OFDate*)fireDate
{
	[self retain];
	@try {
		@synchronized (self) {
			OFDate *old;

			[_inRunLoop OF_removeTimer: self];

			old = _fireDate;
			_fireDate = [fireDate copy];
			[old release];

			[_inRunLoop addTimer: self];
		}
	} @finally {
		[self release];
	}
}






- (void)invalidate
{
	_valid = false;

	[_target release];
	[_object1 release];
	[_object2 release];
	_target = nil;
	_object1 = nil;
	_object2 = nil;
}






#ifdef OF_HAVE_THREADS
- (void)waitUntilDone
{
	[_condition lock];
	@try {
		if (_done) {
			_done = false;
			return;
		}

		[_condition wait];
	} @finally {
		[_condition unlock];
	}
}
#endif





@end