Fix error selectinmg earliest timer.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@25776 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2007-12-22 18:10:12 +00:00
parent ab9404b6a3
commit e78de57d02
2 changed files with 36 additions and 8 deletions

View file

@ -1,3 +1,7 @@
2007-12-22 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSRunLoop.m: Fix error finding earliest timer for limit date.
2007-12-21 Richard Frith-Macdonald <rfm@gnu.org> 2007-12-21 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSLocale.m: protect locale access with locks. * Source/GSLocale.m: protect locale access with locks.

View file

@ -797,7 +797,10 @@ static inline BOOL timerInvalidated(NSTimer *t)
extern NSTimeInterval GSTimeNow(void); extern NSTimeInterval GSTimeNow(void);
GSIArray timers = context->timers; GSIArray timers = context->timers;
NSTimeInterval now; NSTimeInterval now;
NSDate *earliest = nil;
NSTimeInterval ei;
NSTimer *t; NSTimer *t;
NSTimeInterval ti;
unsigned i; unsigned i;
/* /*
@ -858,10 +861,15 @@ static inline BOOL timerInvalidated(NSTimer *t)
} }
d = timerDate(t); d = timerDate(t);
if ([d timeIntervalSinceReferenceDate] > now) ti = [d timeIntervalSinceReferenceDate];
if (ti > now)
{ {
when = [d copy]; if (earliest == nil || ti < ei)
break; {
ei = ti;
earliest = d;
}
continue;
} }
/* When firing the timer we must remove it from /* When firing the timer we must remove it from
@ -888,29 +896,45 @@ static inline BOOL timerInvalidated(NSTimer *t)
} }
if (timerInvalidated(t) == NO) if (timerInvalidated(t) == NO)
{ {
NSDate *next = timerDate(t);
/* Increment fire date unless the timeout handler /* Increment fire date unless the timeout handler
* has already updated it. Then put the timer back * has already updated it. Then put the timer back
* in the array so that it can fire again next * in the array so that it can fire again next
* time this method is called. * time this method is called.
*/ */
if (timerDate(t) == d) if (next == d)
{ {
d = [[NSDate alloc] next = [[NSDate alloc]
initWithTimeIntervalSinceReferenceDate: initWithTimeIntervalSinceReferenceDate:
now + [t timeInterval]]; now + [t timeInterval]];
[t setFireDate: d]; [t setFireDate: next];
RELEASE(d); RELEASE(next);
} }
GSIArrayInsertItemNoRetain(timers, (GSIArrayItem)((id)t), i); GSIArrayInsertItemNoRetain(timers, (GSIArrayItem)((id)t), i);
ti = [next timeIntervalSinceReferenceDate];
if (earliest == nil || ti < ei)
{
ei = ti;
earliest = next;
}
} }
else else
{ {
/* The timer was invalidated, so we can release it as we /* The timer was invalidated, so we can release it as we
* aren't p[utting it back in the array. * aren't putting it back in the array.
*/ */
RELEASE(t); RELEASE(t);
} }
} }
/* The earliest date of a valid timeout is copied into 'when'
* and used as our limit date.
*/
if (earliest != nil)
{
when = [earliest copy];
}
_currentMode = savedMode; _currentMode = savedMode;
} }
NS_HANDLER NS_HANDLER