pike.git/
src/
builtin_functions.c
Branch:
Tag:
Non-build tags
All tags
No tags
1998-05-06
1998-05-06 00:37:09 by Fredrik Hübinette (Hubbe) <hubbe@hubbe.net>
89b07255f92a24f3cf4f84c8787e2bd44edf32f8 (
85
lines) (+
41
/-
44
)
[
Show
|
Annotate
]
Branch:
7.9
sleep() rewritten
Rev: src/builtin_functions.c:1.104
4:
||| See the files COPYING and DISCLAIMER for more information. \*/ #include "global.h"
-
RCSID("$Id: builtin_functions.c,v 1.
103
1998/
04
/
29
00:
29
:
53
grubba
Exp $");
+
RCSID("$Id: builtin_functions.c,v 1.
104
1998/
05
/
06
00:
37
:
09
hubbe
Exp $");
#include "interpret.h" #include "svalue.h" #include "pike_macros.h"
36:
#include "module.h" #include "opcodes.h" #include "cyclic.h"
+
#include "signal_handler.h"
#ifdef HAVE_POLL #ifdef HAVE_POLL_H
1195:
} }
+
#ifndef HAVE_AND_USE_POLL
+
#undef HAVE_POLL
+
#endif
+
void f_sleep(INT32 args) {
-
#ifdef HAVE_POLL
-
int ms;
-
-
if(!args)
-
PIKE_ERROR("sleep", "Too few arguments.\n", sp, args);
-
-
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:
-
PIKE_ERROR("sleep", "Bad argument 1.\n", sp, args);
-
break;
-
}
-
-
THREADS_ALLOW();
-
poll(NULL, 0, ms);
-
THREADS_DISALLOW();
-
-
#else /* !HAVE_POLL */
+
struct timeval t1,t2,t3; INT32 a,b; if(!args) PIKE_ERROR("sleep", "Too few arguments.\n", sp, args);
-
GETTIMEOFDAY(&t1);
-
+
switch(sp[-args].type) { case T_INT:
1247:
default: PIKE_ERROR("sleep", "Bad argument 1.\n", sp, args); }
+
pop_n_elems(args);
-
+
+
if( args >1 && !IS_ZERO(sp-args+1))
+
{
+
THREADS_ALLOW();
+
#ifdef __NT__
+
Sleep(t2.tv_sec * 1000 + t2.tv_usec / 1000);
+
#elif defined(HAVE_POLL)
+
poll(NULL, 0, t2.tv_sec * 1000 + t2.tv_usec / 1000);
+
#else
+
select(0,0,0,0,&t2);
+
#endif
+
THREADS_DISALLOW();
+
}else{
+
GETTIMEOFDAY(&t1);
my_add_timeval(&t1, &t2);
-
pop_n_elems(args);
-
-
#if 0
+
while(1) {
-
#endif /* 0 */
+
GETTIMEOFDAY(&t2); if(my_timercmp(&t1, <= , &t2)) return;
1264:
my_subtract_timeval(&t3, &t2); THREADS_ALLOW();
+
#ifdef __NT__
+
Sleep(t3.tv_sec * 1000 + t3.tv_usec / 1000);
+
#elif defined(HAVE_POLL)
+
poll(NULL, 0, t3.tv_sec * 1000 + t3.tv_usec / 1000);
+
#else
select(0,0,0,0,&t3);
-
+
#endif
THREADS_DISALLOW();
-
#if
0
+
check_signals(
0
,0,0);
}
-
#endif /* 0 */
-
#endif /* HAVE_POLL */
+
}
-
+
}
void f_gc(INT32 args) {
2755:
add_efun("rows",f_rows,"function(mixed,array:array)",0); add_efun("rusage", f_rusage, "function(:int *)",OPT_EXTERNAL_DEPEND); add_efun("search",f_search,"function(string,string,void|int:int)|function(array,mixed,void|int:int)|function(mapping,mixed:mixed)",0);
-
add_efun("sleep", f_sleep, "function(float|int:void)",OPT_SIDE_EFFECT);
+
add_efun("sleep", f_sleep, "function(float|int
,int|void
:void)",OPT_SIDE_EFFECT);
add_efun("sort",f_sort,"function(array(0=mixed),array(mixed)...:array(0))",OPT_SIDE_EFFECT); add_function("splice",f_splice,"function(array(0=mixed)...:array(0))", 0); add_efun("stringp", f_stringp, "function(mixed:int)",0);