mirror of
https://github.com/gnustep/libs-base.git
synced 2025-06-02 09:31:07 +00:00
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:
parent
7c8e06d58e
commit
99a9887e35
1 changed files with 46 additions and 72 deletions
|
@ -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,53 @@ updateTimer(NSTimer *t, NSDate *d, NSTimeInterval now)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* Remove invalidated timers.
|
||||||
* Handle normal timers ... remove invalidated timers and fire one
|
*/
|
||||||
* whose date has passed.
|
i = GSIArrayCount(timers);
|
||||||
|
while (i-- > 0)
|
||||||
|
{
|
||||||
|
t = GSIArrayItemAtIndex(timers, i).obj;
|
||||||
|
if (timerInvalidated(t) == YES)
|
||||||
|
{
|
||||||
|
GSIArrayRemoveItemAtIndex(timers, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Fire the oldest timer whose fire date has passed.
|
||||||
|
*/
|
||||||
|
c = GSIArrayCount(timers);
|
||||||
|
for (i = 0; i < c; i++)
|
||||||
|
{
|
||||||
|
t = GSIArrayItemAtIndex(timers, i).obj;
|
||||||
|
d = timerDate(t);
|
||||||
|
ti = [d timeIntervalSinceReferenceDate];
|
||||||
|
if (ti < now)
|
||||||
|
{
|
||||||
|
GSIArrayRemoveItemAtIndexNoRelease(timers, i);
|
||||||
|
[t fire];
|
||||||
|
GSPrivateNotifyASAP(); /* Post notifications. */
|
||||||
|
IF_NO_GC([arp emptyPool]);
|
||||||
|
if (updateTimer(t, d, now) == YES)
|
||||||
|
{
|
||||||
|
/* Updated ... replace in array.
|
||||||
|
*/
|
||||||
|
GSIArrayAddItemNoRetain(timers, (GSIArrayItem)((id)t));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* The timer was invalidated, so we can
|
||||||
|
* release it as we aren't putting it back
|
||||||
|
* in the array.
|
||||||
|
*/
|
||||||
|
RELEASE(t);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Now, find the earliest fire date.
|
||||||
*/
|
*/
|
||||||
earliest = nil;
|
earliest = nil;
|
||||||
et = nil;
|
|
||||||
i = GSIArrayCount(timers);
|
i = GSIArrayCount(timers);
|
||||||
while (i-- > 0)
|
while (i-- > 0)
|
||||||
{
|
{
|
||||||
|
@ -971,73 +1012,6 @@ updateTimer(NSTimer *t, NSDate *d, NSTimeInterval now)
|
||||||
{
|
{
|
||||||
earliest = d;
|
earliest = d;
|
||||||
ei = ti;
|
ei = ti;
|
||||||
et = t;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If the earliest date is in the past, we should fire the timer.
|
|
||||||
*/
|
|
||||||
if (et != nil && ei < now)
|
|
||||||
{
|
|
||||||
/* 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;
|
|
||||||
if (t == et)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
GSIArrayRemoveItemAtIndexNoRelease(timers, i);
|
|
||||||
[et fire];
|
|
||||||
GSPrivateNotifyASAP(); /* Post notifications. */
|
|
||||||
IF_NO_GC([arp emptyPool]);
|
|
||||||
if (updateTimer(et, earliest, now) == YES)
|
|
||||||
{
|
|
||||||
/* Updated ... replace in array.
|
|
||||||
*/
|
|
||||||
GSIArrayAddItemNoRetain(timers, (GSIArrayItem)((id)et));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* The timer was invalidated, so we can
|
|
||||||
* release it as we aren't putting it back
|
|
||||||
* in the array.
|
|
||||||
*/
|
|
||||||
RELEASE(et);
|
|
||||||
}
|
|
||||||
earliest = nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Now, if we have no earliest date it may be because a timer fired,
|
|
||||||
* in which case we must look again to see what the new earliest
|
|
||||||
* date is.
|
|
||||||
*/
|
|
||||||
if (earliest == nil && (i = GSIArrayCount(timers)) > 0)
|
|
||||||
{
|
|
||||||
while (i-- > 0)
|
|
||||||
{
|
|
||||||
t = GSIArrayItemAtIndex(timers, i).obj;
|
|
||||||
if (timerInvalidated(t) == YES)
|
|
||||||
{
|
|
||||||
GSIArrayRemoveItemAtIndex(timers, i);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
d = timerDate(t);
|
|
||||||
ti = [d timeIntervalSinceReferenceDate];
|
|
||||||
if (earliest == nil || ti < ei)
|
|
||||||
{
|
|
||||||
earliest = d;
|
|
||||||
ei = ti;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue