Improve code for sleeping a bit.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@17244 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2003-07-17 09:00:31 +00:00
parent 97d8f4c387
commit 8a854b2141
6 changed files with 2644 additions and 1581 deletions

View file

@ -1,3 +1,11 @@
2003-07-17 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSRunLoop.m: ([-acceptInputForMode:beforeDate:]) use the
NSThread method to sleep rather than re-implementing it.
* configure.ac: Check for nanosleep()
* Headers/Foundation/config.h.in: Add entry for nanosleep
* Source/NSThread.m: Use nanosleep if available.
2003-07-16 David Ayers <d.ayers@inode.at> 2003-07-16 David Ayers <d.ayers@inode.at>
* config.make.in: Default to builing -baseadd on non *-gnu-* * config.make.in: Default to builing -baseadd on non *-gnu-*

View file

@ -291,6 +291,9 @@
/* Define to 1 if you have the <unistd.h> header file. */ /* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H #undef HAVE_UNISTD_H
/* Define to 1 if you have the `nanosleep' function. */
#undef HAVE_NANOSLEEP
/* Define to 1 if you have the `usleep' function. */ /* Define to 1 if you have the `usleep' function. */
#undef HAVE_USLEEP #undef HAVE_USLEEP

View file

@ -1926,36 +1926,11 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
NSDebugMLLog(@"NSRunLoop", @"no inputs in mode %@", mode); NSDebugMLLog(@"NSRunLoop", @"no inputs in mode %@", mode);
GSNotifyASAP(); GSNotifyASAP();
GSNotifyIdle(); GSNotifyIdle();
ti = [limit_date timeIntervalSinceNow];
/* /*
* Pause for as long as possible (up to the limit date) * Pause for as long as possible (up to the limit date)
*/ */
if (ti > 0.0) [NSThread sleepUntilDate: limit_date];
{ ti = [limit_date timeIntervalSinceNow];
#if defined(HAVE_USLEEP)
if (ti >= INT_MAX / 1000000)
{
ti = INT_MAX;
}
else
{
ti *= 1000000;
}
usleep (ti);
#elif defined(__MINGW__)
if (ti >= INT_MAX / 1000)
{
ti = INT_MAX;
}
else
{
ti *= 1000;
}
Sleep (ti);
#else
sleep (ti);
#endif
}
GSCheckTasks(); GSCheckTasks();
if (context != nil) if (context != nil)
{ {

View file

@ -35,6 +35,9 @@
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif #endif
#ifdef HAVE_NANOSLEEP
#include <time.h>
#endif
#include "Foundation/NSThread.h" #include "Foundation/NSThread.h"
#include "Foundation/NSLock.h" #include "Foundation/NSLock.h"
@ -495,21 +498,24 @@ gnustep_base_thread_callback()
while (delay > 30.0*60.0) while (delay > 30.0*60.0)
{ {
// sleep 30 minutes // sleep 30 minutes
#ifdef HAVE_USLEEP
usleep (30*60*1000000);
#else
#if defined(__MINGW__) #if defined(__MINGW__)
Sleep (30*60*1000); Sleep (30*60*1000);
#else #else
sleep (30*60); sleep (30*60);
#endif
#endif #endif
delay = [date timeIntervalSinceNow]; delay = [date timeIntervalSinceNow];
} }
// usleep may return early because of signals // sleeping may return early because of signals
while (delay > 0) while (delay > 0)
{ {
#ifdef HAVE_NANOSLEEP
struct timespec req;
req.tv_sec = (time_t)delay;
req.tv_nsec = (long)((delay - req.tv_sec) * 1000000000);
nanosleep(&req, 0);
#else
#ifdef HAVE_USLEEP #ifdef HAVE_USLEEP
usleep ((int)(delay*1000000)); usleep ((int)(delay*1000000));
#else #else
@ -518,6 +524,7 @@ gnustep_base_thread_callback()
#else #else
sleep ((int)delay); sleep ((int)delay);
#endif #endif
#endif
#endif #endif
delay = [date timeIntervalSinceNow]; delay = [date timeIntervalSinceNow];
} }

4090
configure vendored

File diff suppressed because it is too large Load diff

View file

@ -645,9 +645,9 @@ AC_CHECK_HEADERS(libc.h limits.h malloc.h memory.h string.h signal.h dnl
sys/ioctl.h sys/stropts.h unistd.h utime.h stdint.h sys/inttypes.h) sys/ioctl.h sys/stropts.h unistd.h utime.h stdint.h sys/inttypes.h)
#-------------------------------------------------------------------- #--------------------------------------------------------------------
# This function needed by NSThread.m # One of these function needed by NSThread.m
#-------------------------------------------------------------------- #--------------------------------------------------------------------
AC_CHECK_FUNCS(usleep) AC_CHECK_FUNCS(nanosleep usleep)
#-------------------------------------------------------------------- #--------------------------------------------------------------------
# This function needed by NSDebug.m and NSProcessInfo.m # This function needed by NSDebug.m and NSProcessInfo.m