summaryrefslogtreecommitdiffstats
path: root/winsup
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2003-01-22 10:43:39 +0000
committerCorinna Vinschen <corinna@vinschen.de>2003-01-22 10:43:39 +0000
commit89f7e8d1d3a52ac824cfc10fdaaa213f43b4c121 (patch)
tree77bc3f5967d4e4b3d71bf10a8db1b2b179fbbfc4 /winsup
parent13afd798c32c94b45f06603bb420bcb1823c5c96 (diff)
downloadcygnal-89f7e8d1d3a52ac824cfc10fdaaa213f43b4c121.tar.gz
cygnal-89f7e8d1d3a52ac824cfc10fdaaa213f43b4c121.tar.bz2
cygnal-89f7e8d1d3a52ac824cfc10fdaaa213f43b4c121.zip
* cygwin.din: Export nanosleep().
* signal.cc (nanosleep): New function. (sleep): Move old functionality to nanosleep(). Call nanosleep(). (usleep): Remove old functionality. Call nanosleep(). * include/cygwin/version.h: Bump API minor number.
Diffstat (limited to 'winsup')
-rw-r--r--winsup/cygwin/ChangeLog10
-rw-r--r--winsup/cygwin/cygwin.din2
-rw-r--r--winsup/cygwin/include/cygwin/version.h3
-rw-r--r--winsup/cygwin/signal.cc65
4 files changed, 54 insertions, 26 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 3f1a04fd0..e3b4da447 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,11 @@
+2003-01-21 Jason Tishler <jason@tishler.net>
+
+ * cygwin.din: Export nanosleep().
+ * signal.cc (nanosleep): New function.
+ (sleep): Move old functionality to nanosleep(). Call nanosleep().
+ (usleep): Remove old functionality. Call nanosleep().
+ * include/cygwin/version.h: Bump API minor number.
+
2003-01-21 Christopher Faylor <cgf@redhat.com>
* grp.cc: Call gr.refresh() rather than doing isunitialized tests
@@ -26,7 +34,7 @@
2003-01-21 Christopher Faylor <cgf@redhat.com>
- * include/cygwin/version.h: Bump DLL minor number.
+ * include/cygwin/version.h: Bump DLL minor number.
2003-01-21 Pierre Humblet <pierre.humblet@ieee.org>
diff --git a/winsup/cygwin/cygwin.din b/winsup/cygwin/cygwin.din
index 499caa5ba..e13923f74 100644
--- a/winsup/cygwin/cygwin.din
+++ b/winsup/cygwin/cygwin.din
@@ -597,6 +597,8 @@ nan
_nan = nan
nanf
_nanf = nanf
+nanosleep
+_nanosleep = nanosleep
nextafter
_nextafter = nextafter
nextafterf
diff --git a/winsup/cygwin/include/cygwin/version.h b/winsup/cygwin/include/cygwin/version.h
index 1b370fa5f..1a10b7be9 100644
--- a/winsup/cygwin/include/cygwin/version.h
+++ b/winsup/cygwin/include/cygwin/version.h
@@ -169,12 +169,13 @@ details. */
69: Export strtof
70: Export asprintf, _asprintf_r, vasprintf, _vasprintf_r
71: Export strerror_r
+ 72: Export nanosleep
*/
/* Note that we forgot to bump the api for ualarm, strtoll, strtoull */
#define CYGWIN_VERSION_API_MAJOR 0
-#define CYGWIN_VERSION_API_MINOR 71
+#define CYGWIN_VERSION_API_MINOR 72
/* There is also a compatibity version number associated with the
shared memory regions. It is incremented when incompatible
diff --git a/winsup/cygwin/signal.cc b/winsup/cygwin/signal.cc
index 106cedb56..5cadc22bc 100644
--- a/winsup/cygwin/signal.cc
+++ b/winsup/cygwin/signal.cc
@@ -66,46 +66,63 @@ signal (int sig, _sig_func_ptr func)
return prev;
}
-extern "C" unsigned int
-sleep (unsigned int seconds)
+extern "C" int
+nanosleep (const struct timespec *rqtp, struct timespec *rmtp)
{
- int rc;
+ int res = 0;
sig_dispatch_pending (0);
sigframe thisframe (mainthread);
- DWORD ms, start_time, end_time;
-
pthread_testcancel ();
- ms = seconds * 1000;
- start_time = GetTickCount ();
- end_time = start_time + (seconds * 1000);
- syscall_printf ("sleep (%d)", seconds);
+ if (rqtp->tv_sec < 0 || rqtp->tv_nsec < 0 || 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;
+ syscall_printf ("nanosleep (%ld)", req);
- rc = pthread::cancelable_wait (signal_arrived, ms);
+ int rc = pthread::cancelable_wait (signal_arrived, req);
DWORD now = GetTickCount ();
- if (rc == WAIT_TIMEOUT || now >= end_time)
- ms = 0;
- else
- ms = end_time - now;
+ DWORD rem = (rc == WAIT_TIMEOUT || now >= end_time) ? 0 : end_time - now;
if (WaitForSingleObject (signal_arrived, 0) == WAIT_OBJECT_0)
- (void) thisframe.call_signal_handler ();
+ {
+ (void) thisframe.call_signal_handler ();
+ set_errno (EINTR);
+ res = -1;
+ }
- DWORD res = (ms + 500) / 1000;
- syscall_printf ("%d = sleep (%d)", res, seconds);
+ if (rmtp)
+ {
+ rmtp->tv_sec = rem / 1000;
+ rmtp->tv_nsec = (rem % 1000) * 1000000;
+ }
+ syscall_printf ("%d = nanosleep (%ld, %ld)", res, req, rem);
return res;
}
extern "C" unsigned int
-usleep (unsigned int useconds)
+sleep (unsigned int seconds)
{
- pthread_testcancel ();
+ struct timespec req, rem;
+ req.tv_sec = seconds;
+ req.tv_nsec = 0;
+ nanosleep (&req, &rem);
+ return rem.tv_sec + (rem.tv_nsec + 500000000) / 1000000000;
+}
- sig_dispatch_pending (0);
- syscall_printf ("usleep (%d)", useconds);
- pthread::cancelable_wait (signal_arrived, (useconds + 500) / 1000);
- syscall_printf ("0 = usleep (%d)", useconds);
- return 0;
+extern "C" unsigned int
+usleep (unsigned int useconds)
+{
+ struct timespec req;
+ req.tv_sec = useconds / 1000000;
+ req.tv_nsec = (useconds % 1000000) * 1000;
+ int res = nanosleep (&req, 0);
+ return res;
}
extern "C" int