From: Kurt Zeilenga Date: Fri, 6 Jan 2006 19:47:59 +0000 (+0000) Subject: Replace sched_yield(2) on Linux with select(2) (ITS#3950) X-Git-Tag: OPENLDAP_REL_ENG_2_3_16~14 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=ed898b28cd19eb01c386e2b898a400ac8b889164;p=openldap Replace sched_yield(2) on Linux with select(2) (ITS#3950) --- diff --git a/CHANGES b/CHANGES index 3e54c35d13..679e46e4ca 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,8 @@ OpenLDAP 2.3 Change Log OpenLDAP 2.3.16 Engineering + Build environment + Replace sched_yield(2) on Linux with select(2) (ITS#3950) OpenLDAP 2.3.15 Release Fixed slapd strerror logging bug (ITS#4292) diff --git a/configure b/configure index 57c920c4d5..91164f73c4 100755 --- a/configure +++ b/configure @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.in OpenLDAP: pkg/ldap/configure.in,v 1.560.2.18 2005/11/26 17:01:54 kurt Exp . +# From configure.in OpenLDAP: pkg/ldap/configure.in,v 1.560.2.20 2006/01/03 22:16:00 kurt Exp . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.59. # @@ -24740,6 +24740,21 @@ echo "${ECHO_T}$ol_cv_pthread_create_works" >&6 { { echo "$as_me:$LINENO: error: pthread_create is not usable, check environment settings" >&5 echo "$as_me: error: pthread_create is not usable, check environment settings" >&2;} { (exit 1); exit 1; }; } + fi + + ol_replace_broken_yield=no + case "$target" in + *-*-linux*) + ol_replace_broken_yield=yes + ;; + esac + + if test $ol_replace_broken_yield = yes ; then + +cat >>confdefs.h <<\_ACEOF +#define REPLACE_BROKEN_YIELD 1 +_ACEOF + fi if test $ol_with_yielding_select = auto ; then @@ -42898,7 +42913,6 @@ fi - for ac_func in \ @@ -42950,7 +42964,6 @@ for ac_func in \ strtoll \ strspn \ sysconf \ - usleep \ waitpid \ wait4 \ write \ diff --git a/configure.in b/configure.in index 3192c25873..728040b499 100644 --- a/configure.in +++ b/configure.in @@ -1585,6 +1585,18 @@ dnl [ol_cv_pthread_lpthread_lexc]) AC_MSG_ERROR([pthread_create is not usable, check environment settings]) fi + ol_replace_broken_yield=no + case "$target" in + *-*-linux*) + ol_replace_broken_yield=yes + ;; + esac + + if test $ol_replace_broken_yield = yes ; then + AC_DEFINE([REPLACE_BROKEN_YIELD],1, + [define if sched_yield yields the entire process]) + fi + dnl Check if select causes an yield if test $ol_with_yielding_select = auto ; then AC_CACHE_CHECK([if select yields when using pthreads], @@ -2564,7 +2576,6 @@ AC_CHECK_FUNCS( \ strtoll \ strspn \ sysconf \ - usleep \ waitpid \ wait4 \ write \ diff --git a/include/portable.hin b/include/portable.hin index 69ce9a7cae..d1576801b6 100644 --- a/include/portable.hin +++ b/include/portable.hin @@ -777,9 +777,6 @@ /* Define to 1 if you have the header file. */ #undef HAVE_UNISTD_H -/* Define to 1 if you have the `usleep' function. */ -#undef HAVE_USLEEP - /* Define to 1 if you have the header file. */ #undef HAVE_UTIME_H @@ -903,6 +900,9 @@ /* Define to the version of this package. */ #undef PACKAGE_VERSION +/* define if sched_yield yields the entire process */ +#undef REPLACE_BROKEN_YIELD + /* Define as the return type of signal handlers (`int' or `void'). */ #undef RETSIGTYPE diff --git a/libraries/libldap_r/thr_posix.c b/libraries/libldap_r/thr_posix.c index 2a05236399..c867e5715b 100644 --- a/libraries/libldap_r/thr_posix.c +++ b/libraries/libldap_r/thr_posix.c @@ -20,6 +20,13 @@ #include +#ifdef REPLACE_BROKEN_YIELD +#ifndef HAVE_NANOSLEEP +#include +#endif +#include +#endif + #include "ldap_pvt_thread.h" /* Get the thread interface */ #define LDAP_THREAD_IMPLEMENTATION #define LDAP_THREAD_RDWR_IMPLEMENTATION @@ -207,7 +214,16 @@ ldap_pvt_thread_kill( ldap_pvt_thread_t thread, int signo ) int ldap_pvt_thread_yield( void ) { -#if HAVE_THR_YIELD +#ifdef REPLACE_BROKEN_YIELD +#ifdef HAVE_NANOSLEEP + struct timespec t = { 0, 0 }; + nanosleep(&t, NULL); +#else + struct timeval tv = {0,0}; + select( 0, NULL, NULL, NULL, &tv ); +#endif + return 0; +#elif HAVE_THR_YIELD return thr_yield(); #elif HAVE_PTHREADS == 10