mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-09 21:40:33 +02:00
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.
This commit is contained in:
parent
da7532528c
commit
6aa9316dea
1 changed files with 18 additions and 42 deletions
|
@ -40,7 +40,7 @@
|
||||||
* If you do not wish that, delete this exception notice. */
|
* 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 */
|
/* Cooperative thread library, based on QuickThreads */
|
||||||
|
|
||||||
|
@ -51,20 +51,6 @@
|
||||||
#include <qt.h>
|
#include <qt.h>
|
||||||
#include "eval.h"
|
#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 (0x10000) */
|
||||||
#define COOP_STKSIZE (scm_eval_stack)
|
#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
|
/* Replacement for the system's sleep() function. Does the right thing
|
||||||
for the process - but not for the system (it busy-waits) */
|
for the process - but not for the system (it busy-waits) */
|
||||||
|
|
||||||
#ifdef __STDC__
|
|
||||||
void *
|
void *
|
||||||
coop_sleephelp (qt_t *sp, void *old, void *blockq)
|
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;
|
((coop_t *)old)->sp = sp;
|
||||||
/* old is already on the sleep queue - so there's no need to
|
/* 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 GUILE_ISELECT
|
||||||
|
|
||||||
#ifdef USLEEP_RETURNS_VOID
|
unsigned long
|
||||||
void
|
scm_thread_usleep (unsigned long usec)
|
||||||
#else
|
|
||||||
int
|
|
||||||
#endif
|
|
||||||
usleep (USLEEP_ARG_TYPE usec)
|
|
||||||
{
|
{
|
||||||
struct timeval timeout;
|
struct timeval timeout;
|
||||||
timeout.tv_sec = 0;
|
timeout.tv_sec = 0;
|
||||||
timeout.tv_usec = usec;
|
timeout.tv_usec = usec;
|
||||||
scm_internal_select (0, NULL, NULL, NULL, &timeout);
|
scm_internal_select (0, NULL, NULL, NULL, &timeout);
|
||||||
#ifndef USLEEP_RETURNS_VOID
|
|
||||||
return 0; /* Maybe we should calculate actual time slept,
|
return 0; /* Maybe we should calculate actual time slept,
|
||||||
but this is faster... :) */
|
but this is faster... :) */
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned
|
unsigned long
|
||||||
sleep (unsigned sec)
|
scm_thread_sleep (unsigned long sec)
|
||||||
{
|
{
|
||||||
time_t now = time (NULL);
|
time_t now = time (NULL);
|
||||||
struct timeval timeout;
|
struct timeval timeout;
|
||||||
int slept;
|
unsigned long slept;
|
||||||
timeout.tv_sec = sec;
|
timeout.tv_sec = sec;
|
||||||
timeout.tv_usec = 0;
|
timeout.tv_usec = 0;
|
||||||
scm_internal_select (0, NULL, NULL, NULL, &timeout);
|
scm_internal_select (0, NULL, NULL, NULL, &timeout);
|
||||||
|
@ -700,14 +672,8 @@ sleep (unsigned sec)
|
||||||
|
|
||||||
#else /* GUILE_ISELECT */
|
#else /* GUILE_ISELECT */
|
||||||
|
|
||||||
#ifdef __STDC__
|
unsigned long
|
||||||
unsigned
|
scm_thread_sleep (unsigned long s)
|
||||||
sleep (unsigned s)
|
|
||||||
#else
|
|
||||||
unsigned
|
|
||||||
sleep (s)
|
|
||||||
unsigned s;
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
coop_t *newthread, *old;
|
coop_t *newthread, *old;
|
||||||
time_t now = time (NULL);
|
time_t now = time (NULL);
|
||||||
|
@ -730,4 +696,14 @@ sleep (s)
|
||||||
return 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 */
|
#endif /* GUILE_ISELECT */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue