From d49b134654dd76ff0b3a178feadbde41e206683b Mon Sep 17 00:00:00 2001 From: jgarcia Date: Mon, 10 Dec 2007 19:17:45 +0000 Subject: [PATCH] Implemented mp_process_yield (Built on Dan Corkill's patches) --- msvc/ecl-threads.def | 1 + msvc/ecl/config.h.msvc6 | 2 + src/c/symbols_list.h | 1 + src/c/symbols_list2.h | 1 + src/c/threads.d | 14 +++++ src/c/threads_win32.d | 14 +++++ src/configure | 111 ++++++++++++++++++++++++++++++++++++++++ src/configure.in | 2 + src/h/config.h.in | 2 + src/h/external.h | 1 + 10 files changed, 149 insertions(+) diff --git a/msvc/ecl-threads.def b/msvc/ecl-threads.def index 6aed3ff67..b3e835dc3 100755 --- a/msvc/ecl-threads.def +++ b/msvc/ecl-threads.def @@ -1073,6 +1073,7 @@ EXPORTS mp_make_process mp_process_active_p mp_process_enable + mp_process_yield ;mp_process_interrupt mp_process_kill mp_process_name diff --git a/msvc/ecl/config.h.msvc6 b/msvc/ecl/config.h.msvc6 index 3cc094531..1d7904163 100644 --- a/msvc/ecl/config.h.msvc6 +++ b/msvc/ecl/config.h.msvc6 @@ -211,6 +211,8 @@ typedef unsigned int uint32_t; #define HAVE_LONG_LONG 1 /* the tzset() function gets the current time zone */ #define HAVE_TZSET 1 +/* whether we have sched_yield() that gives priority to other threads */ +/* #undef HAVE_SCHED_YIELD */ /* what characters are used to mark beginning of new line */ #define ECL_NEWLINE_IS_CRLF 1 diff --git a/src/c/symbols_list.h b/src/c/symbols_list.h index 3cb8027f5..c2afcebe3 100644 --- a/src/c/symbols_list.h +++ b/src/c/symbols_list.h @@ -1504,6 +1504,7 @@ cl_symbols[] = { {MP_ "MAKE-PROCESS", MP_ORDINARY, mp_make_process, -1, OBJNULL}, {MP_ "PROCESS-ACTIVE-P", MP_ORDINARY, mp_process_active_p, 1, OBJNULL}, {MP_ "PROCESS-ENABLE", MP_ORDINARY, mp_process_enable, 1, OBJNULL}, +{MP_ "PROCESS-YIELD", MP_ORDINARY, mp_process_yield, 0, OBJNULL}, {MP_ "PROCESS-KILL", MP_ORDINARY, mp_process_kill, 1, OBJNULL}, {MP_ "PROCESS-NAME", MP_ORDINARY, mp_process_name, 1, OBJNULL}, {MP_ "PROCESS-PRESET", MP_ORDINARY, mp_process_preset, -1, OBJNULL}, diff --git a/src/c/symbols_list2.h b/src/c/symbols_list2.h index 5db0bf450..81995ac37 100644 --- a/src/c/symbols_list2.h +++ b/src/c/symbols_list2.h @@ -1504,6 +1504,7 @@ cl_symbols[] = { {MP_ "MAKE-PROCESS","mp_make_process"}, {MP_ "PROCESS-ACTIVE-P","mp_process_active_p"}, {MP_ "PROCESS-ENABLE","mp_process_enable"}, +{MP_ "PROCESS-YIELD","mp_process_yield"}, {MP_ "PROCESS-KILL","mp_process_kill"}, {MP_ "PROCESS-NAME","mp_process_name"}, {MP_ "PROCESS-PRESET","mp_process_preset"}, diff --git a/src/c/threads.d b/src/c/threads.d index a57571c7d..07a0bfd50 100644 --- a/src/c/threads.d +++ b/src/c/threads.d @@ -26,6 +26,9 @@ #ifdef HAVE_GETTIMEOFDAY # include #endif +#ifdef HAVE_SCHED_YIELD +# include +#endif #ifndef WITH___THREAD static pthread_key_t cl_env_key; @@ -207,6 +210,17 @@ mp_process_kill(cl_object process) @(return Ct) } +cl_object +mp_process_yield(void) +{ +#ifdef HAVE_SCHED_YIELD + sched_yield(); +#else + sleep(0); /* Use sleep(0) to yield to a >= priority thread */ +#endif + @(return) +} + cl_object mp_process_enable(cl_object process) { diff --git a/src/c/threads_win32.d b/src/c/threads_win32.d index b82dfb57e..3792c3443 100644 --- a/src/c/threads_win32.d +++ b/src/c/threads_win32.d @@ -18,6 +18,9 @@ #include #include #include +#ifdef HAVE_SCHED_YIELD +# include +#endif /* * We have to put this explicit definition here because Boehm GC @@ -219,6 +222,17 @@ mp_process_kill(cl_object process) return mp_interrupt_process(process, @'mp::exit-process'); } +cl_object +mp_process_yield(void) +{ +#ifdef HAVE_SCHED_YIELD + sched_yield(); +#else + sleep(0); /* Use sleep(0) to yield to a >= priority thread */ +#endif + @(return) +} + cl_object mp_process_enable(cl_object process) { diff --git a/src/configure b/src/configure index ce8aaa44c..e52406eed 100755 --- a/src/configure +++ b/src/configure @@ -11775,6 +11775,117 @@ done +for ac_func in sched_yield +do +as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` +{ echo "$as_me:$LINENO: checking for $ac_func" >&5 +echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6; } +if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +/* Define $ac_func to an innocuous variant, in case declares $ac_func. + For example, HP-UX 11i declares gettimeofday. */ +#define $ac_func innocuous_$ac_func + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $ac_func (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include +#else +# include +#endif + +#undef $ac_func + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char $ac_func (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined __stub_$ac_func || defined __stub___$ac_func +choke me +#endif + +int +main () +{ +return $ac_func (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + eval "$as_ac_var=yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + eval "$as_ac_var=no" +fi + +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +ac_res=`eval echo '${'$as_ac_var'}'` + { echo "$as_me:$LINENO: result: $ac_res" >&5 +echo "${ECHO_T}$ac_res" >&6; } +if test `eval echo '${'$as_ac_var'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +fi +done + + + if test ${with_cxx} = "no" ; then ECL_CC=${CC} diff --git a/src/configure.in b/src/configure.in index 0cf55f4f4..938dacdf3 100644 --- a/src/configure.in +++ b/src/configure.in @@ -446,6 +446,8 @@ AC_CHECK_FUNCS( [nanosleep alarm times isnanf select setenv putenv] \ AC_CHECK_FUNCS( [expf logf sqrtf cosf sinf tanf sinhf coshf tanhf] \ [floorf ceilf fabsf frexpf ldexpf]) +AC_CHECK_FUNCS( [sched_yield] ) + dnl ===================================================================== dnl Checks for system services diff --git a/src/h/config.h.in b/src/h/config.h.in index 7dc667ec7..fa8351e57 100644 --- a/src/h/config.h.in +++ b/src/h/config.h.in @@ -247,6 +247,8 @@ typedef unsigned @CL_FIXNUM_TYPE@ cl_hashkey; #undef HAVE_FABSF #undef HAVE_FREXPF #undef HAVE_LDEXPF +/* whether we have sched_yield() that gives priority to other threads */ +#undef HAVE_SCHED_YIELD /* * we do not manage to get proper signal handling of floating point diff --git a/src/h/external.h b/src/h/external.h index 3bee31c99..f295a2311 100644 --- a/src/h/external.h +++ b/src/h/external.h @@ -1394,6 +1394,7 @@ extern cl_object mp_interrupt_process(cl_object process, cl_object function); extern cl_object mp_make_process _ARGS((cl_narg narg, ...)); extern cl_object mp_process_active_p(cl_object process); extern cl_object mp_process_enable(cl_object process); +extern cl_object mp_process_yield(void); extern cl_object mp_process_interrupt(cl_object process, cl_object function); extern cl_object mp_process_kill(cl_object process); extern cl_object mp_process_name(cl_object process);