From 6aa9316dea8f1eb68a36c590ded0460ab9fcd28b Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Tue, 13 Oct 1998 23:17:09 +0000 Subject: [PATCH] Don't redefine sleep and usleep. * coop.c (sleep, usleep): Remove declarations; we don't use or redefine these any more. (scm_thread_usleep, scm_thread_sleep): New functions which do the job of usleep and sleep in a thread-friendly way. We can use these in the rest of Guile. Define versions for systems both with and without iselect. * coop.c (scm_thread_sleep): Make `slept' an unsigned long. * coop.c (coop_sleephelp): Remove ANSI #ifdef hair. --- libguile/coop.c | 60 +++++++++++++++---------------------------------- 1 file changed, 18 insertions(+), 42 deletions(-) diff --git a/libguile/coop.c b/libguile/coop.c index 0cb1bea0e..d69f32133 100644 --- a/libguile/coop.c +++ b/libguile/coop.c @@ -40,7 +40,7 @@ * If you do not wish that, delete this exception notice. */ -/* $Id: coop.c,v 1.13 1998-10-12 21:08:36 jimb Exp $ */ +/* $Id: coop.c,v 1.14 1998-10-13 23:17:09 jimb Exp $ */ /* Cooperative thread library, based on QuickThreads */ @@ -51,20 +51,6 @@ #include #include "eval.h" -/* Provide declarations for these, if the system does not. */ - -#if defined(MISSING_SLEEP_DECL) -extern unsigned int sleep (unsigned int); -#endif - -#if defined(MISSING_USLEEP_DECL) -#ifdef USLEEP_RETURNS_VOID -extern void usleep (USLEEP_ARG_TYPE); -#else -extern int usleep (USLEEP_ARG_TYPE); -#endif -#endif - /* #define COOP_STKSIZE (0x10000) */ #define COOP_STKSIZE (scm_eval_stack) @@ -649,16 +635,8 @@ coop_yieldhelp (sp, old, blockq) /* Replacement for the system's sleep() function. Does the right thing for the process - but not for the system (it busy-waits) */ -#ifdef __STDC__ void * coop_sleephelp (qt_t *sp, void *old, void *blockq) -#else -void * -coop_sleephelp (sp, old, bolckq) - qt_t *sp; - void *old; - void *blockq; -#endif { ((coop_t *)old)->sp = sp; /* old is already on the sleep queue - so there's no need to @@ -668,29 +646,23 @@ coop_sleephelp (sp, old, bolckq) #ifdef GUILE_ISELECT -#ifdef USLEEP_RETURNS_VOID -void -#else -int -#endif -usleep (USLEEP_ARG_TYPE usec) +unsigned long +scm_thread_usleep (unsigned long usec) { struct timeval timeout; timeout.tv_sec = 0; timeout.tv_usec = usec; scm_internal_select (0, NULL, NULL, NULL, &timeout); -#ifndef USLEEP_RETURNS_VOID return 0; /* Maybe we should calculate actual time slept, but this is faster... :) */ -#endif } -unsigned -sleep (unsigned sec) +unsigned long +scm_thread_sleep (unsigned long sec) { time_t now = time (NULL); struct timeval timeout; - int slept; + unsigned long slept; timeout.tv_sec = sec; timeout.tv_usec = 0; scm_internal_select (0, NULL, NULL, NULL, &timeout); @@ -700,14 +672,8 @@ sleep (unsigned sec) #else /* GUILE_ISELECT */ -#ifdef __STDC__ -unsigned -sleep (unsigned s) -#else -unsigned -sleep (s) - unsigned s; -#endif +unsigned long +scm_thread_sleep (unsigned long s) { coop_t *newthread, *old; time_t now = time (NULL); @@ -730,4 +696,14 @@ sleep (s) return s; } +unsigned long +scm_thread_usleep (unsigned long usec) +{ + /* We're so cheap. */ + scm_thread_sleep (usec / 1000000); + struct timeval timeout; + return 0; /* Maybe we should calculate actual time slept, + but this is faster... :) */ +} + #endif /* GUILE_ISELECT */