* src/RunLoop.m ([RunLoop -limitDateForMode:]):

Various changes to get timeouts working reliably.
	Ensure that _current_mode is restored correctly on exit.

        * src/RunLoop.m ([RunLoop -acceptInputForMode:beforeDate:]):
	Ensure that _current_mode is restored correctly on exit.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@2015 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
mccallum 1997-01-06 22:21:02 +00:00
parent bd119c71f6
commit 4a657ff30c

View file

@ -1,5 +1,5 @@
/* Implementation of object for waiting on several input sources /* Implementation of object for waiting on several input sources
Copyright (C) 1996 Free Software Foundation, Inc. Copyright (C) 1996, 1997 Free Software Foundation, Inc.
Written by: Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu> Written by: Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
Created: March 1996 Created: March 1996
@ -21,6 +21,10 @@
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* October 1996 - extensions to permit file descriptors to be watched
for being readable or writable added by Richard Frith-Macdonald
(richard@brainstorm.co.uk) */
/* This is the beginning of a RunLoop implementation. /* This is the beginning of a RunLoop implementation.
It is still in the early stages of development, and will most likely It is still in the early stages of development, and will most likely
evolve quite a bit more before the interface settles. evolve quite a bit more before the interface settles.
@ -318,7 +322,7 @@ static RunLoop *current_run_loop;
{ {
/* Linux doesn't always return double from methods, even though /* Linux doesn't always return double from methods, even though
I'm using -lieee. */ I'm using -lieee. */
#if 1 #if 0
assert (mode); assert (mode);
return nil; return nil;
#else #else
@ -331,28 +335,44 @@ static RunLoop *current_run_loop;
timers = NSMapGet (_mode_2_timers, mode); timers = NSMapGet (_mode_2_timers, mode);
if (!timers) if (!timers)
return nil;
/* Does this properly handle timers that have been sent -invalidate? */
while ((min_timer = [timers minObject])
&& ([[min_timer fireDate] timeIntervalSinceNow] > 0))
{ {
_current_mode = saved_mode;
return nil;
}
/* Does this properly handle timers that have been sent -invalidate? */
while ((min_timer = [timers minObject]) != nil)
{
if (![min_timer isValid])
{
[timers removeFirstObject];
min_timer = nil;
continue;
}
if ([[min_timer fireDate] timeIntervalSinceNow] > 0)
break;
[min_timer retain]; [min_timer retain];
[timers removeFirstObject]; [timers removeFirstObject];
/* Firing will also increment its fireDate, if it is repeating. */ /* Firing will also increment its fireDate, if it is repeating. */
[min_timer fire];
if ([min_timer isValid]) if ([min_timer isValid])
{ {
[min_timer fire]; if ([[min_timer fireDate] timeIntervalSinceNow] > 0)
if ([[min_timer fireDate] timeIntervalSinceNow] < 0)
[timers addObject: min_timer]; [timers addObject: min_timer];
} }
[min_timer release]; [min_timer release];
min_timer = nil;
} }
_current_mode = saved_mode;
if (min_timer == nil)
return nil;
if (debug_run_loop) if (debug_run_loop)
printf ("\tRunLoop limit date %f\n", printf ("\tRunLoop limit date %f\n",
[[min_timer fireDate] timeIntervalSinceReferenceDate]); [[min_timer fireDate] timeIntervalSinceReferenceDate]);
_current_mode = saved_mode;
return [min_timer fireDate]; return [min_timer fireDate];
#endif #endif
} }
@ -384,7 +404,10 @@ static RunLoop *current_run_loop;
#if 0 #if 0
/* If there are no input sources to listen to, just return. */ /* If there are no input sources to listen to, just return. */
if (NSCountMapTable (_fd_2_object) == 0) if (NSCountMapTable (_fd_2_object) == 0)
return; {
_current_mode = saved_mode;
return;
}
#endif #endif
/* Find out how much time we should wait, and set SELECT_TIMEOUT. */ /* Find out how much time we should wait, and set SELECT_TIMEOUT. */
@ -407,6 +430,7 @@ static RunLoop *current_run_loop;
{ {
if (debug_run_loop) if (debug_run_loop)
printf ("\tRunLoop limit date past, returning\n"); printf ("\tRunLoop limit date past, returning\n");
_current_mode = saved_mode;
return; return;
} }
timeout.tv_sec = ti; timeout.tv_sec = ti;
@ -417,6 +441,7 @@ static RunLoop *current_run_loop;
{ {
/* The LIMIT_DATE has already past; return immediately without /* The LIMIT_DATE has already past; return immediately without
polling any inputs. */ polling any inputs. */
_current_mode = saved_mode;
return; return;
} }
else else
@ -524,6 +549,7 @@ static RunLoop *current_run_loop;
else if (select_return == 0) else if (select_return == 0)
{ {
NSFreeMapTable (fd_2_object); NSFreeMapTable (fd_2_object);
_current_mode = saved_mode;
return; return;
} }