From a737a8e65f078b96eb63a478fdc8517b373e5435 Mon Sep 17 00:00:00 2001 From: Andrew McCallum Date: Tue, 19 Mar 1996 17:10:41 +0000 Subject: [PATCH] ([RunLoop -acceptInputForMode:beforeDate:]): If LIMIT_DATE is nil, poll the inputs, but don't wait if there is nothing available immediately. Check to make sure that the LIMIT_DATE hasn't already past; if it has, return immediately, before polling input sources. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@1220 72102866-910b-0410-8b05-ffd578937521 --- Source/RunLoop.m | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/Source/RunLoop.m b/Source/RunLoop.m index 72fa203c4..f4cc4c6f9 100644 --- a/Source/RunLoop.m +++ b/Source/RunLoop.m @@ -25,7 +25,6 @@ It is still in the early stages of development, and will most likely evolve quite a bit more before the interface settles. - Distinguishing between different MODES is not currently implemented. Handling NSTimers is implemented, but currently disabled. Does it strike anyone else that NSNotificationCenter, @@ -239,7 +238,8 @@ static RunLoop *current_run_loop; } -/* Listen to input sources */ +/* Listen to input sources. + If LIMIT_DATE is nil, then don't wait; i.e. call select() with 0 timeout */ - (void) acceptInputForMode: (id )mode beforeDate: limit_date @@ -267,9 +267,17 @@ static RunLoop *current_run_loop; #endif /* Find out how much time we should wait, and set SELECT_TIMEOUT. */ - if (limit_date - && ((ti = [limit_date timeIntervalSinceNow]) < LONG_MAX)) + if (!limit_date) { + /* Don't wait at all. */ + timeout.tv_sec = 0; + timeout.tv_usec = 0; + select_timeout = &timeout; + } + else if ((ti = [limit_date timeIntervalSinceNow]) < LONG_MAX + && ti > 0.0) + { + /* Wait until the LIMIT_DATE. */ if (debug_run_loop) printf ("\tRunLoop accept input before %f (seconds from now %f)\n", [limit_date timeIntervalSinceReferenceDate], ti); @@ -280,13 +288,19 @@ static RunLoop *current_run_loop; printf ("\tRunLoop limit date past, returning\n"); return; } - timeout.tv_sec = ti; timeout.tv_usec = ti * 1000000.0; select_timeout = &timeout; } + else if (ti <= 0.0) + { + /* The LIMIT_DATE has already past; return immediately without + polling any inputs. */ + return; + } else { + /* Wait forever. */ if (debug_run_loop) printf ("\tRunLoop accept input waiting forever\n"); select_timeout = NULL; @@ -401,6 +415,10 @@ static RunLoop *current_run_loop; [self acceptInputForMode: mode beforeDate: d]; + /* xxx Is this where we detect if the RunLoop is idle, and whether + we should dispatch the notifications from NotificationQueue's + idle queue? */ + return YES; }