openldap-thread-check.m4 [plain text]
AC_DEFUN([OL_THREAD_CHECK], [
AC_REQUIRE([AC_CANONICAL_HOST])
AC_LANG_SAVE
AC_LANG([C])
OL_ARG_WITH(threads,[ --with-threads with threads],
auto, [auto nt posix mach pth lwp yes no manual] )
case "$ol_with_threads$host" in
auto*-*-solaris2.[[0-6]])
ol_with_threads=no
;;
esac
ol_aix_threads=no
case "$host" in
*-*-aix*) if test -z "$CC" ; then
case "$ol_with_threads" in
auto | yes | posix) ol_aix_threads=yes ;;
esac
fi
;;
esac
if test $ol_aix_threads = yes ; then
if test -z "${CC}" ; then
AC_CHECK_PROGS(CC,cc_r xlc_r cc)
if test "$CC" = cc ; then
if test $ol_with_threads != auto ; then
AC_MSG_ERROR([--with-threads requires cc_r (or other suitable compiler) on AIX])
else
AC_MSG_WARN([disabling threads, no cc_r on AIX])
fi
ol_with_threads=no
fi
fi
case ${CC} in cc_r | xlc_r)
ol_with_threads=posix
ol_cv_pthread_create=yes
;;
esac
fi
ol_link_threads=no
OL_ARG_WITH(yielding_select,[ --with-yielding-select with yielding select],
auto, [auto yes no manual] )
case $ol_with_threads in auto | yes | nt)
OL_NT_THREADS
if test "$ol_cv_nt_threads" = yes ; then
ol_link_threads=nt
ol_with_threads=found
ol_with_yielding_select=yes
AC_DEFINE([HAVE_NT_SERVICE_MANAGER], [1], [if you have NT Service Manager])
AC_DEFINE([HAVE_NT_EVENT_LOG], [1], [if you have NT Event Log])
fi
if test $ol_with_threads = nt ; then
AC_MSG_ERROR([could not locate NT Threads])
fi
;;
esac
case $ol_with_threads in auto | yes | posix)
AC_CHECK_HEADERS(pthread.h)
if test $ac_cv_header_pthread_h = yes ; then
OL_POSIX_THREAD_VERSION
if test $ol_cv_pthread_version != 0 ; then
AC_DEFINE_UNQUOTED([HAVE_PTHREADS], [$ol_cv_pthread_version],
[define to pthreads API spec revision])
else
AC_MSG_ERROR([unknown pthread version])
fi
ol_with_threads=found
OL_HEADER_LINUX_THREADS
OL_HEADER_GNU_PTH_PTHREAD_H
if test $ol_cv_header_gnu_pth_pthread_h = no ; then
AC_CHECK_HEADERS(sched.h)
fi
AC_CACHE_CHECK([for pthread_create in default libraries],
ol_cv_pthread_create,[
AC_RUN_IFELSE([OL_PTHREAD_TEST_PROGRAM],
[ol_cv_pthread_create=yes],
[ol_cv_pthread_create=no],
[AC_TRY_LINK(OL_PTHREAD_TEST_INCLUDES,OL_PTHREAD_TEST_FUNCTION,
[ol_cv_pthread_create=yes],
[ol_cv_pthread_create=no])])])
if test $ol_cv_pthread_create != no ; then
ol_link_threads=posix
ol_link_pthreads=""
fi
OL_PTHREAD_TRY([-kthread], [ol_cv_pthread_kthread])
OL_PTHREAD_TRY([-pthread], [ol_cv_pthread_pthread])
OL_PTHREAD_TRY([-pthreads], [ol_cv_pthread_pthreads])
OL_PTHREAD_TRY([-mthreads], [ol_cv_pthread_mthreads])
OL_PTHREAD_TRY([-thread], [ol_cv_pthread_thread])
OL_PTHREAD_TRY([-lpthread -lmach -lexc -lc_r],
[ol_cv_pthread_lpthread_lmach_lexc_lc_r])
OL_PTHREAD_TRY([-lpthread -lmach -lexc],
[ol_cv_pthread_lpthread_lmach_lexc])
OL_PTHREAD_TRY([-lpthread -Wl,-woff,85],
[ol_cv_pthread_lib_lpthread_woff])
OL_PTHREAD_TRY([-lpthread], [ol_cv_pthread_lpthread])
OL_PTHREAD_TRY([-lc_r], [ol_cv_pthread_lc_r])
OL_PTHREAD_TRY([-threads], [ol_cv_pthread_threads])
OL_PTHREAD_TRY([-lpthreads -lmach -lexc -lc_r],
[ol_cv_pthread_lpthreads_lmach_lexc_lc_r])
OL_PTHREAD_TRY([-lpthreads -lmach -lexc],
[ol_cv_pthread_lpthreads_lmach_lexc])
OL_PTHREAD_TRY([-lpthreads -lexc],
[ol_cv_pthread_lpthreads_lexc])
OL_PTHREAD_TRY([-lpthreads],[ol_cv_pthread_lib_lpthreads])
AC_MSG_NOTICE([ol_link_threads: <$ol_link_threads> ol_link_pthreads <$ol_link_pthreads>])
if test $ol_link_threads != no ; then
LTHREAD_LIBS="$LTHREAD_LIBS $ol_link_pthreads"
save_CPPFLAGS="$CPPFLAGS"
save_LIBS="$LIBS"
LIBS="$LTHREAD_LIBS $LIBS"
AC_CHECK_FUNCS(sched_yield pthread_yield thr_yield)
if test $ac_cv_func_sched_yield = no &&
test $ac_cv_func_pthread_yield = no &&
test $ac_cv_func_thr_yield = no ; then
AC_CHECK_LIB(rt, sched_yield,
[LTHREAD_LIBS="$LTHREAD_LIBS -lrt"
AC_DEFINE([HAVE_SCHED_YIELD], [1],
[Define if you have the sched_yield function.])
ac_cv_func_sched_yield=yes],
[ac_cv_func_sched_yield=no])
fi
if test $ac_cv_func_sched_yield = no &&
test $ac_cv_func_pthread_yield = no &&
test "$ac_cv_func_thr_yield" = no ; then
AC_MSG_WARN([could not locate sched_yield() or pthread_yield()])
fi
AC_CHECK_FUNCS(pthread_kill)
AC_CACHE_CHECK([for pthread_rwlock_destroy with <pthread.h>],
[ol_cv_func_pthread_rwlock_destroy], [
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
pthread_rwlock_t rwlock;
]], [[pthread_rwlock_destroy(&rwlock);]])],[ol_cv_func_pthread_rwlock_destroy=yes],[ol_cv_func_pthread_rwlock_destroy=no])
])
if test $ol_cv_func_pthread_rwlock_destroy = yes ; then
AC_DEFINE([HAVE_PTHREAD_RWLOCK_DESTROY], [1],
[define if you have pthread_rwlock_destroy function])
fi
AC_CACHE_CHECK([for pthread_detach with <pthread.h>],
[ol_cv_func_pthread_detach], [
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
]], [[pthread_detach(NULL);]])],[ol_cv_func_pthread_detach=yes],[ol_cv_func_pthread_detach=no])
])
if test $ol_cv_func_pthread_detach = no ; then
AC_MSG_ERROR([could not locate pthread_detach()])
fi
AC_DEFINE([HAVE_PTHREAD_DETACH], [1],
[define if you have pthread_detach function])
AC_CHECK_FUNCS( \
pthread_setconcurrency \
pthread_getconcurrency \
thr_setconcurrency \
thr_getconcurrency \
)
OL_SYS_LINUX_THREADS
OL_LINUX_THREADS
if test $ol_cv_linux_threads = error; then
AC_MSG_ERROR([LinuxThreads header/library mismatch]);
fi
AC_CACHE_CHECK([if pthread_create() works],
ol_cv_pthread_create_works,[
AC_RUN_IFELSE([OL_PTHREAD_TEST_PROGRAM],
[ol_cv_pthread_create_works=yes],
[ol_cv_pthread_create_works=no],
[ ol_cv_pthread_create_works=yes])])
if test $ol_cv_pthread_create_works = no ; then
AC_MSG_ERROR([pthread_create is not usable, check environment settings])
fi
ol_replace_broken_yield=no
if test $ol_replace_broken_yield = yes ; then
AC_DEFINE([REPLACE_BROKEN_YIELD], [1],
[define if sched_yield yields the entire process])
fi
if test x$ol_with_yielding_select = xauto ; then
AC_CACHE_CHECK([if select yields when using pthreads],
ol_cv_pthread_select_yields,[
AC_RUN_IFELSE([AC_LANG_SOURCE([[
static int fildes[2];
static void *task(p)
void *p;
{
int i;
struct timeval tv;
fd_set rfds;
tv.tv_sec=10;
tv.tv_usec=0;
FD_ZERO(&rfds);
FD_SET(fildes[0], &rfds);
/* we're not interested in any fds */
i = select(FD_SETSIZE, &rfds, NULL, NULL, &tv);
if(i < 0) {
perror("select");
exit(10);
}
exit(0); /* if we exit here, the select blocked the whole process */
}
int main(argc, argv)
int argc;
char **argv;
{
pthread_t t;
/* create a pipe to select */
if(pipe(&fildes[0])) {
perror("select");
exit(1);
}
(void) pthread_setconcurrency(2);
/* Set Solaris LWP concurrency to 2 */
thr_setconcurrency(2);
pthread_create(&t, pthread_attr_default, task, NULL);
pthread_create(&t, NULL, task, NULL);
/* make sure task runs first */
thr_yield();
sched_yield();
pthread_yield();
exit(2);
}]])],[ol_cv_pthread_select_yields=no],[ol_cv_pthread_select_yields=yes],[ol_cv_pthread_select_yields=cross])])
if test $ol_cv_pthread_select_yields = cross ; then
AC_MSG_ERROR([crossing compiling: use --with-yielding-select=yes|no|manual])
fi
if test $ol_cv_pthread_select_yields = yes ; then
ol_with_yielding_select=yes
fi
fi
CPPFLAGS="$save_CPPFLAGS"
LIBS="$save_LIBS"
else
AC_MSG_ERROR([could not locate usable POSIX Threads])
fi
fi
if test $ol_with_threads = posix ; then
AC_MSG_ERROR([could not locate POSIX Threads])
fi
;;
esac
case $ol_with_threads in auto | yes | mach)
AC_CHECK_HEADERS(mach/cthreads.h cthreads.h)
if test $ac_cv_header_mach_cthreads_h = yes ; then
ol_with_threads=found
AC_CHECK_FUNC(cthread_fork,[ol_link_threads=yes])
if test $ol_link_threads = no ; then
AC_CACHE_CHECK([for cthread_fork with -all_load],
[ol_cv_cthread_all_load], [
save_LIBS="$LIBS"
LIBS="-all_load $LIBS"
AC_LINK_IFELSE([AC_LANG_PROGRAM([[ cthread_fork((void *)0, (void *)0);
]])],[ol_cv_cthread_all_load=yes],[ol_cv_cthread_all_load=no])
LIBS="$save_LIBS"
])
if test $ol_cv_cthread_all_load = yes ; then
LTHREAD_LIBS="$LTHREAD_LIBS -all_load"
ol_link_threads=mach
ol_with_threads=found
fi
fi
elif test $ac_cv_header_cthreads_h = yes ; then
ol_with_threads=found
save_LIBS="$LIBS"
LIBS="$LIBS -lthreads"
AC_CHECK_FUNC(cthread_fork,[ol_link_threads=yes])
LIBS="$save_LIBS"
if test $ol_link_threads = yes ; then
LTHREAD_LIBS="-lthreads"
ol_link_threads=mach
ol_with_threads=found
else
AC_MSG_ERROR([could not link with Mach CThreads])
fi
elif test $ol_with_threads = mach ; then
AC_MSG_ERROR([could not locate Mach CThreads])
fi
if test $ol_link_threads = mach ; then
AC_DEFINE([HAVE_MACH_CTHREADS], [1],
[define if you have Mach Cthreads])
elif test $ol_with_threads = found ; then
AC_MSG_ERROR([could not link with Mach CThreads])
fi
;;
esac
case $ol_with_threads in auto | yes | pth)
AC_CHECK_HEADERS(pth.h)
if test $ac_cv_header_pth_h = yes ; then
AC_CHECK_LIB(pth, pth_version, [have_pth=yes], [have_pth=no])
if test $have_pth = yes ; then
AC_DEFINE([HAVE_GNU_PTH], [1], [if you have GNU Pth])
LTHREAD_LIBS="$LTHREAD_LIBS -lpth"
ol_link_threads=pth
ol_with_threads=found
if test x$ol_with_yielding_select = xauto ; then
ol_with_yielding_select=yes
fi
fi
fi
;;
esac
case $ol_with_threads in auto | yes | lwp)
AC_CHECK_HEADERS(thread.h synch.h)
if test $ac_cv_header_thread_h = yes &&
test $ac_cv_header_synch_h = yes ; then
AC_CHECK_LIB(thread, thr_create, [have_thr=yes], [have_thr=no])
if test $have_thr = yes ; then
AC_DEFINE([HAVE_THR], [1],
[if you have Solaris LWP (thr) package])
LTHREAD_LIBS="$LTHREAD_LIBS -lthread"
ol_link_threads=thr
if test x$ol_with_yielding_select = xauto ; then
ol_with_yielding_select=yes
fi
AC_CHECK_FUNCS( \
thr_setconcurrency \
thr_getconcurrency \
)
fi
fi
AC_CHECK_HEADERS(lwp/lwp.h)
if test $ac_cv_header_lwp_lwp_h = yes ; then
AC_CHECK_LIB(lwp, lwp_create, [have_lwp=yes], [have_lwp=no])
if test $have_lwp = yes ; then
AC_DEFINE([HAVE_LWP], [1],
[if you have SunOS LWP package])
LTHREAD_LIBS="$LTHREAD_LIBS -llwp"
ol_link_threads=lwp
if test x$ol_with_yielding_select = xauto ; then
ol_with_yielding_select=no
fi
fi
fi
;;
esac
if test $ol_with_yielding_select = yes ; then
AC_DEFINE([HAVE_YIELDING_SELECT], [1],
[define if select implicitly yields])
fi
if test $ol_with_threads = manual ; then
ol_link_threads=yes
AC_MSG_WARN([thread defines and link options must be set manually])
AC_CHECK_HEADERS(pthread.h sched.h)
AC_CHECK_FUNCS(sched_yield pthread_yield)
OL_HEADER_LINUX_THREADS
AC_CHECK_HEADERS(mach/cthreads.h)
AC_CHECK_HEADERS(lwp/lwp.h)
AC_CHECK_HEADERS(thread.h synch.h)
fi
if test $ol_link_threads != no && test $ol_link_threads != nt ; then
AC_DEFINE([REENTRANT], [1], [enable thread safety])
AC_DEFINE([_REENTRANT], [1], [enable thread safety])
AC_DEFINE([THREAD_SAFE], [1], [enable thread safety])
AC_DEFINE([_THREAD_SAFE], [1], [enable thread safety])
AC_DEFINE([THREADSAFE], [1], [enable thread safety])
AC_DEFINE([_THREADSAFE], [1], [enable thread safety])
AC_DEFINE([_SGI_MP_SOURCE], [1], [enable thread safety])
AC_CACHE_CHECK([for thread specific errno],
[ol_cv_errno_thread_specific], [
AC_LINK_IFELSE([AC_LANG_PROGRAM([[ ])
AC_CACHE_CHECK([for thread specific h_errno],
[ol_cv_h_errno_thread_specific], [
AC_LINK_IFELSE([AC_LANG_PROGRAM([[ ])
if test $ol_cv_errno_thread_specific != yes ||
test $ol_cv_h_errno_thread_specific != yes ; then
LIBS="$LTHREAD_LIBS $LIBS"
LTHREAD_LIBS=""
fi
fi
if test $ol_link_threads = no ; then
if test $ol_with_threads = yes ; then
AC_MSG_ERROR([no suitable thread support])
fi
if test $ol_with_threads = auto ; then
AC_MSG_WARN([no suitable thread support, disabling threads])
ol_with_threads=no
fi
AC_DEFINE([NO_THREADS], [1],
[define if you have (or want) no threads])
LTHREAD_LIBS=""
BUILD_THREAD=no
else
BUILD_THREAD=yes
fi
if test $ol_link_threads != no ; then
AC_DEFINE([LDAP_API_FEATURE_X_OPENLDAP_THREAD_SAFE], [1],
[define to 1 if library is thread safe])
fi
case "$ol_with_threads" in
no)
ol_pthread_ok=no
$2
;;
*)
ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])
;;
esac
AC_LANG_RESTORE
AC_SUBST(BUILD_THREAD)
AC_SUBST(LTHREAD_LIBS)
])