From b48f28fdcde28c7cf788a3b489bd54cec9fdfae2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Grubbstr=C3=B6m=20=28Grubba=29?= <grubba@grubba.org> Date: Thu, 26 Mar 1998 14:20:29 +0100 Subject: [PATCH] sleep() now allows for signals to break the sleep. sleep() now uses poll(2) on some OS's. Rev: src/builtin_functions.c:1.88 --- src/builtin_functions.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/builtin_functions.c b/src/builtin_functions.c index 7860a3b939..82311af1e7 100644 --- a/src/builtin_functions.c +++ b/src/builtin_functions.c @@ -4,7 +4,7 @@ ||| See the files COPYING and DISCLAIMER for more information. \*/ #include "global.h" -RCSID("$Id: builtin_functions.c,v 1.87 1998/03/20 22:31:04 hubbe Exp $"); +RCSID("$Id: builtin_functions.c,v 1.88 1998/03/26 13:20:29 grubba Exp $"); #include "interpret.h" #include "svalue.h" #include "pike_macros.h" @@ -1172,6 +1172,29 @@ void f_functionp(INT32 args) void f_sleep(INT32 args) { +#ifdef HAVE_POLL + int ms; + + if(!args) + error("Too few arguments to sleep.\n"); + + switch(sp[-args].type) { + case T_INT: + ms = sp[-args].u.integer * 1000; + break; + case T_FLOAT: + ms = (int)(sp[-args].u.float_number * 1000.0); + break; + default: + error("Bad argument 1 to sleep.\n"); + break; + } + + THREADS_ALLOW(); + poll(NULL, 0, ms); + THREADS_DISALLOW(); + +#else /* !HAVE_POLL */ struct timeval t1,t2,t3; INT32 a,b; @@ -1203,11 +1226,14 @@ void f_sleep(INT32 args) my_add_timeval(&t1, &t2); pop_n_elems(args); + +#if 0 while(1) { +#endif /* 0 */ GETTIMEOFDAY(&t2); if(my_timercmp(&t1, <= , &t2)) - break; + return; t3=t1; my_subtract_timeval(&t3, &t2); @@ -1215,8 +1241,10 @@ void f_sleep(INT32 args) THREADS_ALLOW(); select(0,0,0,0,&t3); THREADS_DISALLOW(); - check_threads_etc(); +#if 0 } +#endif /* 0 */ +#endif /* HAVE_POLL */ } void f_gc(INT32 args) -- GitLab