1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-12 14:50:19 +02:00

* 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.
This commit is contained in:
Jim Blandy 1998-10-13 23:17:34 +00:00
parent 6aa9316dea
commit b74f472891
3 changed files with 41 additions and 21 deletions

View file

@ -167,21 +167,18 @@
/* Define if the operating system supplies bzero without declaring it. */ /* Define if the operating system supplies bzero without declaring it. */
#undef MISSING_BZERO_DECL #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. */ /* Define if the operating system supplies sleep without declaring it. */
#undef MISSING_SLEEP_DECL #undef MISSING_SLEEP_DECL
/* Define if the operating system supplies usleep without declaring it. */ /* Define if the operating system supplies usleep without declaring it. */
#undef MISSING_USLEEP_DECL #undef MISSING_USLEEP_DECL
/* Define if the operating system supplies strptime without declaring it. */ /* Define if the system headers declare usleep to return void. */
#undef MISSING_STRPTIME_DECL
/* Define if usleep doesn't return a value. */
#undef USLEEP_RETURNS_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. */ /* Define if your readline library has the rl_getc_function variable. */
#undef HAVE_RL_GETC_FUNCTION #undef HAVE_RL_GETC_FUNCTION

View file

@ -52,12 +52,17 @@
#include <unistd.h> #include <unistd.h>
#endif #endif
#if defined(MISSING_USLEEP_DECL) || (defined(GUILE_ISELECT) && !defined(HAVE_USLEEP)) /* The thread system has its own sleep and usleep functions. */
#ifdef USLEEP_RETURNS_VOID #ifndef USE_THREADS
extern void usleep (USLEEP_ARG_TYPE);
#else #if defined(MISSING_SLEEP_DECL)
extern int usleep (USLEEP_ARG_TYPE); int sleep ();
#endif #endif
#if defined(HAVE_USLEEP) && defined(MISSING_USLEEP_DECL)
int usleep ();
#endif
#endif #endif
@ -353,32 +358,44 @@ SCM
scm_sleep (i) scm_sleep (i)
SCM i; SCM i;
{ {
unsigned int j; unsigned long j;
SCM_ASSERT (SCM_INUMP (i) && (SCM_INUM (i) >= 0), i, SCM_ARG1, s_sleep); 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)); 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_PROC(s_usleep, "usleep", 1, 0, 0, scm_usleep);
SCM SCM
scm_usleep (i) scm_usleep (i)
SCM i; SCM i;
{ {
#ifndef USLEEP_RETURNS_VOID
int j;
#endif
SCM_ASSERT (SCM_INUMP (i) && (SCM_INUM (i) >= 0), i, SCM_ARG1, s_usleep); 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 #ifdef USLEEP_RETURNS_VOID
usleep (SCM_INUM (i)); usleep (SCM_INUM (i));
return SCM_INUM0; return SCM_INUM0;
#else #else
j = usleep (SCM_INUM (i)); {
return SCM_MAKINUM (j); int j = usleep (SCM_INUM (i));
return SCM_MAKINUM (j);
}
#endif
#endif #endif
} }
#endif #endif /* GUILE_ISELECT || HAVE_USLEEP */
SCM_PROC(s_raise, "raise", 1, 0, 0, scm_raise); SCM_PROC(s_raise, "raise", 1, 0, 0, scm_raise);

View file

@ -76,6 +76,12 @@ SCM scm_threads_monitor SCM_P ((void));
SCM scm_spawn_thread (scm_catch_body_t body, void *body_data, SCM scm_spawn_thread (scm_catch_body_t body, void *body_data,
scm_catch_handler_t handler, void *handler_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. */ /* The C versions of the Scheme-visible thread functions. */
#ifdef USE_COOP_THREADS #ifdef USE_COOP_THREADS
extern SCM scm_single_thread_p (void); extern SCM scm_single_thread_p (void);