From b74f4728914a335d841b42d2a8f7968aad0be166 Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Tue, 13 Oct 1998 23:17:34 +0000 Subject: [PATCH] * threads.h (scm_thread_usleep, scm_thread_sleep): New declarations. * scmsigs.c (usleep): Clean up oddities declaring usleep; since we're just using it, not redefining it, we can use a K&R style declaration here. (sleep): Declare this, too, if the system hasn't. (scm_sleep, scm_usleep): Use scm_thread_sleep and scm_uthread_sleep if they're available; otherwise, just call the system functions. * scmconfig.h.in: Regenerated. --- libguile/scmconfig.h.in | 11 ++++------ libguile/scmsigs.c | 45 ++++++++++++++++++++++++++++------------- libguile/threads.h | 6 ++++++ 3 files changed, 41 insertions(+), 21 deletions(-) diff --git a/libguile/scmconfig.h.in b/libguile/scmconfig.h.in index e6e6d245f..1e92f5d9d 100644 --- a/libguile/scmconfig.h.in +++ b/libguile/scmconfig.h.in @@ -167,21 +167,18 @@ /* Define if the operating system supplies bzero without declaring it. */ #undef MISSING_BZERO_DECL +/* Define if the operating system supplies strptime without declaring it. */ +#undef MISSING_STRPTIME_DECL + /* Define if the operating system supplies sleep without declaring it. */ #undef MISSING_SLEEP_DECL /* Define if the operating system supplies usleep without declaring it. */ #undef MISSING_USLEEP_DECL -/* Define if the operating system supplies strptime without declaring it. */ -#undef MISSING_STRPTIME_DECL - -/* Define if usleep doesn't return a value. */ +/* Define if the system headers declare usleep to return void. */ #undef USLEEP_RETURNS_VOID -/* Define to be the type of the argument to usleep. */ -#undef USLEEP_ARG_TYPE - /* Define if your readline library has the rl_getc_function variable. */ #undef HAVE_RL_GETC_FUNCTION diff --git a/libguile/scmsigs.c b/libguile/scmsigs.c index 9d7ced3ce..66cb7fa6a 100644 --- a/libguile/scmsigs.c +++ b/libguile/scmsigs.c @@ -52,12 +52,17 @@ #include #endif -#if defined(MISSING_USLEEP_DECL) || (defined(GUILE_ISELECT) && !defined(HAVE_USLEEP)) -#ifdef USLEEP_RETURNS_VOID -extern void usleep (USLEEP_ARG_TYPE); -#else -extern int usleep (USLEEP_ARG_TYPE); +/* The thread system has its own sleep and usleep functions. */ +#ifndef USE_THREADS + +#if defined(MISSING_SLEEP_DECL) +int sleep (); #endif + +#if defined(HAVE_USLEEP) && defined(MISSING_USLEEP_DECL) +int usleep (); +#endif + #endif @@ -353,32 +358,44 @@ SCM scm_sleep (i) SCM i; { - unsigned int j; + unsigned long j; SCM_ASSERT (SCM_INUMP (i) && (SCM_INUM (i) >= 0), i, SCM_ARG1, s_sleep); +#ifdef USE_THREADS + j = scm_thread_sleep (SCM_INUM(i)); +#else j = sleep (SCM_INUM(i)); - return SCM_MAKINUM (j); +#endif + return scm_ulong2num (j); } -#if defined(GUILE_ISELECT) || defined(HAVE_USLEEP) +#if defined(USE_THREADS) || defined(HAVE_USLEEP) SCM_PROC(s_usleep, "usleep", 1, 0, 0, scm_usleep); SCM scm_usleep (i) SCM i; { -#ifndef USLEEP_RETURNS_VOID - int j; -#endif SCM_ASSERT (SCM_INUMP (i) && (SCM_INUM (i) >= 0), i, SCM_ARG1, s_usleep); + +#ifdef USE_THREADS + /* If we have threads, we use the thread system's sleep function. */ + { + unsigned long j = scm_thread_usleep (SCM_INUM (i)); + return scm_ulong2num (j); + } +#else #ifdef USLEEP_RETURNS_VOID usleep (SCM_INUM (i)); return SCM_INUM0; #else - j = usleep (SCM_INUM (i)); - return SCM_MAKINUM (j); + { + int j = usleep (SCM_INUM (i)); + return SCM_MAKINUM (j); + } +#endif #endif } -#endif +#endif /* GUILE_ISELECT || HAVE_USLEEP */ SCM_PROC(s_raise, "raise", 1, 0, 0, scm_raise); diff --git a/libguile/threads.h b/libguile/threads.h index 5f61b9fbe..9a25e1735 100644 --- a/libguile/threads.h +++ b/libguile/threads.h @@ -76,6 +76,12 @@ SCM scm_threads_monitor SCM_P ((void)); SCM scm_spawn_thread (scm_catch_body_t body, void *body_data, scm_catch_handler_t handler, void *handler_data); +/* These are versions of the ordinary sleep and usleep functions, + that play nicely with the thread system. */ +SCM unsigned long scm_thread_sleep (unsigned long); +SCM unsigned long scm_thread_usleep (unsigned long); + + /* The C versions of the Scheme-visible thread functions. */ #ifdef USE_COOP_THREADS extern SCM scm_single_thread_p (void);