mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-05 22:20:59 +00:00
further simplify and add comments
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@28655 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
99a9887e35
commit
b510b0d659
1 changed files with 34 additions and 36 deletions
|
@ -931,8 +931,7 @@ updateTimer(NSTimer *t, NSDate *d, NSTimeInterval now)
|
||||||
*/
|
*/
|
||||||
now = GSTimeNow();
|
now = GSTimeNow();
|
||||||
|
|
||||||
/*
|
/* Fire housekeeping timer as necessary
|
||||||
* Fire housekeeping timer as necessary
|
|
||||||
*/
|
*/
|
||||||
if ((t = context->housekeeper) != nil)
|
if ((t = context->housekeeper) != nil)
|
||||||
{
|
{
|
||||||
|
@ -949,51 +948,50 @@ updateTimer(NSTimer *t, NSDate *d, NSTimeInterval now)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Remove invalidated timers.
|
/* Fire the oldest/first valid timer whose fire date has passed
|
||||||
*/
|
* and fire it.
|
||||||
i = GSIArrayCount(timers);
|
* We fire timers in the order in which they were added to the
|
||||||
while (i-- > 0)
|
* run loop rather than in date order. This prevents code
|
||||||
{
|
* from blocking other timers by adding timers whose fire date
|
||||||
t = GSIArrayItemAtIndex(timers, i).obj;
|
* is some time in the past... we guarantee fair handling.
|
||||||
if (timerInvalidated(t) == YES)
|
|
||||||
{
|
|
||||||
GSIArrayRemoveItemAtIndex(timers, i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Fire the oldest timer whose fire date has passed.
|
|
||||||
*/
|
*/
|
||||||
c = GSIArrayCount(timers);
|
c = GSIArrayCount(timers);
|
||||||
for (i = 0; i < c; i++)
|
for (i = 0; i < c; i++)
|
||||||
{
|
{
|
||||||
t = GSIArrayItemAtIndex(timers, i).obj;
|
t = GSIArrayItemAtIndex(timers, i).obj;
|
||||||
d = timerDate(t);
|
if (timerInvalidated(t) == NO)
|
||||||
ti = [d timeIntervalSinceReferenceDate];
|
|
||||||
if (ti < now)
|
|
||||||
{
|
{
|
||||||
GSIArrayRemoveItemAtIndexNoRelease(timers, i);
|
d = timerDate(t);
|
||||||
[t fire];
|
ti = [d timeIntervalSinceReferenceDate];
|
||||||
GSPrivateNotifyASAP(); /* Post notifications. */
|
if (ti < now)
|
||||||
IF_NO_GC([arp emptyPool]);
|
|
||||||
if (updateTimer(t, d, now) == YES)
|
|
||||||
{
|
{
|
||||||
/* Updated ... replace in array.
|
GSIArrayRemoveItemAtIndexNoRelease(timers, i);
|
||||||
*/
|
[t fire];
|
||||||
GSIArrayAddItemNoRetain(timers, (GSIArrayItem)((id)t));
|
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;
|
||||||
}
|
}
|
||||||
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.
|
/* Now, find the earliest remaining timer date while removing
|
||||||
|
* any invalidated timers. We iterate from the end of the
|
||||||
|
* array to minimise the amount of array alteration needed.
|
||||||
*/
|
*/
|
||||||
earliest = nil;
|
earliest = nil;
|
||||||
i = GSIArrayCount(timers);
|
i = GSIArrayCount(timers);
|
||||||
|
|
Loading…
Reference in a new issue