summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/signal.cc
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2003-09-07 05:18:01 +0000
committerChristopher Faylor <me@cgf.cx>2003-09-07 05:18:01 +0000
commited2287adcd6b16a0ef34defb443d5c61fc7830d7 (patch)
tree4b567ae87a505f3fb4bc5ba3329db06a1936df78 /winsup/cygwin/signal.cc
parent6cce721b15c6ac75e7d6ae86a4354aa02bcf14d8 (diff)
downloadcygnal-ed2287adcd6b16a0ef34defb443d5c61fc7830d7.tar.gz
cygnal-ed2287adcd6b16a0ef34defb443d5c61fc7830d7.tar.bz2
cygnal-ed2287adcd6b16a0ef34defb443d5c61fc7830d7.zip
* signal.cc (nanosleep): Improve test for valid values. Round delay up to
resolution. Fix test for negative remainder. Use timeGetTime through gtod. (sleep): Round up return value. Christopher Faylor <cgf@redhat.com> * hires.h (HIRES_DELAY_MAX): Define. (hires_ms::minperiod): Declare static. (hires_ms::resolution): New. (hires_ms::dmsecs): New. (hires_ms::prime): Return UINT. (gtod): Declare. * times.cc (hires_ms::prime): Always calculate minperiod and set it to 1 in case of failure. Return minperiod. (hires_ms::resolution): Define. (hires_ms::~hires_ms): Delete. (hires_ms::usecs): Check minperiod to prime. (gtod) Define as global.
Diffstat (limited to 'winsup/cygwin/signal.cc')
-rw-r--r--winsup/cygwin/signal.cc19
1 files changed, 11 insertions, 8 deletions
diff --git a/winsup/cygwin/signal.cc b/winsup/cygwin/signal.cc
index 2b890dd62..133f192b4 100644
--- a/winsup/cygwin/signal.cc
+++ b/winsup/cygwin/signal.cc
@@ -17,6 +17,7 @@ details. */
#include <sys/cygwin.h>
#include "sigproc.h"
#include "pinfo.h"
+#include "hires.h"
int sigcatchers; /* FIXME: Not thread safe. */
@@ -73,20 +74,22 @@ nanosleep (const struct timespec *rqtp, struct timespec *rmtp)
sigframe thisframe (mainthread);
pthread_testcancel ();
- if (rqtp->tv_sec < 0 || rqtp->tv_nsec < 0 || rqtp->tv_nsec > 999999999)
+ if ((unsigned int) rqtp->tv_sec > (HIRES_DELAY_MAX / 1000 - 1)
+ || (unsigned int) rqtp->tv_nsec > 999999999)
{
set_errno (EINVAL);
return -1;
}
-
- DWORD req = rqtp->tv_sec * 1000 + (rqtp->tv_nsec + 500000) / 1000000;
- DWORD start_time = GetTickCount ();
- DWORD end_time = start_time + req;
+ DWORD resolution = gtod.resolution ();
+ DWORD req = ((rqtp->tv_sec * 1000 + (rqtp->tv_nsec + 999999) / 1000000
+ + resolution - 1) / resolution ) * resolution;
+ DWORD end_time = gtod.dmsecs () + req;
syscall_printf ("nanosleep (%ld)", req);
int rc = pthread::cancelable_wait (signal_arrived, req);
- DWORD now = GetTickCount ();
- DWORD rem = (rc == WAIT_TIMEOUT || now >= end_time) ? 0 : end_time - now;
+ DWORD rem;
+ if ((rem = end_time - gtod.dmsecs ()) > HIRES_DELAY_MAX)
+ rem = 0;
if (rc == WAIT_OBJECT_0)
{
(void) thisframe.call_signal_handler ();
@@ -111,7 +114,7 @@ sleep (unsigned int seconds)
req.tv_sec = seconds;
req.tv_nsec = 0;
nanosleep (&req, &rem);
- return rem.tv_sec + (rem.tv_nsec + 500000000) / 1000000000;
+ return rem.tv_sec + (rem.tv_nsec > 0);
}
extern "C" unsigned int