simplified

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@28654 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2009-09-10 14:48:37 +00:00
parent 7c8e06d58e
commit 99a9887e35

View file

@ -913,11 +913,11 @@ updateTimer(NSTimer *t, NSDate *d, NSTimeInterval now)
GSIArray timers = context->timers; GSIArray timers = context->timers;
NSTimeInterval now; NSTimeInterval now;
NSDate *earliest; NSDate *earliest;
NSTimer *et;
NSDate *d; NSDate *d;
NSTimer *t; NSTimer *t;
NSTimeInterval ti; NSTimeInterval ti;
NSTimeInterval ei; NSTimeInterval ei;
unsigned c;
unsigned i; unsigned i;
/* /*
@ -949,12 +949,8 @@ updateTimer(NSTimer *t, NSDate *d, NSTimeInterval now)
} }
} }
/* /* Remove invalidated timers.
* Handle normal timers ... remove invalidated timers and fire one
* whose date has passed.
*/ */
earliest = nil;
et = nil;
i = GSIArrayCount(timers); i = GSIArrayCount(timers);
while (i-- > 0) while (i-- > 0)
{ {
@ -963,47 +959,27 @@ updateTimer(NSTimer *t, NSDate *d, NSTimeInterval now)
{ {
GSIArrayRemoveItemAtIndex(timers, i); GSIArrayRemoveItemAtIndex(timers, i);
} }
else
{
d = timerDate(t);
ti = [d timeIntervalSinceReferenceDate];
if (earliest == nil || ti < ei)
{
earliest = d;
ei = ti;
et = t;
}
}
} }
/* If the earliest date is in the past, we should fire the timer. /* Fire the oldest timer whose fire date has passed.
*/ */
if (et != nil && ei < now) c = GSIArrayCount(timers);
{ for (i = 0; i < c; i++)
/* When firing the timer we must remove it from
* the loop so that if the -fire methods re-runs
* the loop we do not get recursive entry into
* the timer. This appears to be the behavior
* in MacOS-X also.
*/
i = GSIArrayCount(timers);
while (i-- > 0)
{ {
t = GSIArrayItemAtIndex(timers, i).obj; t = GSIArrayItemAtIndex(timers, i).obj;
if (t == et) d = timerDate(t);
ti = [d timeIntervalSinceReferenceDate];
if (ti < now)
{ {
break;
}
}
GSIArrayRemoveItemAtIndexNoRelease(timers, i); GSIArrayRemoveItemAtIndexNoRelease(timers, i);
[et fire]; [t fire];
GSPrivateNotifyASAP(); /* Post notifications. */ GSPrivateNotifyASAP(); /* Post notifications. */
IF_NO_GC([arp emptyPool]); IF_NO_GC([arp emptyPool]);
if (updateTimer(et, earliest, now) == YES) if (updateTimer(t, d, now) == YES)
{ {
/* Updated ... replace in array. /* Updated ... replace in array.
*/ */
GSIArrayAddItemNoRetain(timers, (GSIArrayItem)((id)et)); GSIArrayAddItemNoRetain(timers, (GSIArrayItem)((id)t));
} }
else else
{ {
@ -1011,17 +987,16 @@ updateTimer(NSTimer *t, NSDate *d, NSTimeInterval now)
* release it as we aren't putting it back * release it as we aren't putting it back
* in the array. * in the array.
*/ */
RELEASE(et); RELEASE(t);
}
break;
} }
earliest = nil;
} }
/* Now, if we have no earliest date it may be because a timer fired, /* Now, find the earliest fire date.
* in which case we must look again to see what the new earliest
* date is.
*/ */
if (earliest == nil && (i = GSIArrayCount(timers)) > 0) earliest = nil;
{ i = GSIArrayCount(timers);
while (i-- > 0) while (i-- > 0)
{ {
t = GSIArrayItemAtIndex(timers, i).obj; t = GSIArrayItemAtIndex(timers, i).obj;
@ -1040,7 +1015,6 @@ updateTimer(NSTimer *t, NSDate *d, NSTimeInterval now)
} }
} }
} }
}
/* The earliest date of a valid timeout is copied into 'when' /* The earliest date of a valid timeout is copied into 'when'
* and used as our limit date. * and used as our limit date.