mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 09:04:13 +00:00
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:
parent
11822288e4
commit
a2309a4051
6 changed files with 2644 additions and 1581 deletions
|
@ -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>
|
||||
|
||||
* config.make.in: Default to builing -baseadd on non *-gnu-*
|
||||
|
|
|
@ -291,6 +291,9 @@
|
|||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#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. */
|
||||
#undef HAVE_USLEEP
|
||||
|
||||
|
|
|
@ -1926,36 +1926,11 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
|
|||
NSDebugMLLog(@"NSRunLoop", @"no inputs in mode %@", mode);
|
||||
GSNotifyASAP();
|
||||
GSNotifyIdle();
|
||||
ti = [limit_date timeIntervalSinceNow];
|
||||
/*
|
||||
* Pause for as long as possible (up to the limit date)
|
||||
*/
|
||||
if (ti > 0.0)
|
||||
{
|
||||
#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
|
||||
}
|
||||
[NSThread sleepUntilDate: limit_date];
|
||||
ti = [limit_date timeIntervalSinceNow];
|
||||
GSCheckTasks();
|
||||
if (context != nil)
|
||||
{
|
||||
|
|
|
@ -35,6 +35,9 @@
|
|||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#ifdef HAVE_NANOSLEEP
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
#include "Foundation/NSThread.h"
|
||||
#include "Foundation/NSLock.h"
|
||||
|
@ -495,21 +498,24 @@ gnustep_base_thread_callback()
|
|||
while (delay > 30.0*60.0)
|
||||
{
|
||||
// sleep 30 minutes
|
||||
#ifdef HAVE_USLEEP
|
||||
usleep (30*60*1000000);
|
||||
#else
|
||||
#if defined(__MINGW__)
|
||||
Sleep (30*60*1000);
|
||||
#else
|
||||
sleep (30*60);
|
||||
#endif
|
||||
#endif
|
||||
delay = [date timeIntervalSinceNow];
|
||||
}
|
||||
|
||||
// usleep may return early because of signals
|
||||
// sleeping may return early because of signals
|
||||
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
|
||||
usleep ((int)(delay*1000000));
|
||||
#else
|
||||
|
@ -518,6 +524,7 @@ gnustep_base_thread_callback()
|
|||
#else
|
||||
sleep ((int)delay);
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
delay = [date timeIntervalSinceNow];
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# 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
|
||||
|
|
Loading…
Reference in a new issue