1b5bbe2e3Schristosdnl OpenLDAP Autoconf thread check 2b5bbe2e3Schristosdnl 3b5bbe2e3Schristosdnl This work is part of OpenLDAP Software <http://www.openldap.org/>. 4b5bbe2e3Schristosdnl 5b5bbe2e3Schristosdnl Copyright 1998-2010 The OpenLDAP Foundation. 6b5bbe2e3Schristosdnl All rights reserved. 7b5bbe2e3Schristosdnl 8b5bbe2e3Schristosdnl Redistribution and use in source and binary forms, with or without 9b5bbe2e3Schristosdnl modification, are permitted only as authorized by the OpenLDAP 10b5bbe2e3Schristosdnl Public License. 11b5bbe2e3Schristosdnl 12b5bbe2e3Schristosdnl A copy of this license is available in the file LICENSE-OPENLDAP in 13b5bbe2e3Schristosdnl this directory of the distribution or, alternatively, at 14b5bbe2e3Schristosdnl <http://www.OpenLDAP.org/license.html>. 15b5bbe2e3Schristosdnl 16b5bbe2e3Schristosdnl -------------------------------------------------------------------- 17b5bbe2e3Schristos 18*a6f3f22fSchristosdnl This file is a fragment of OpenLDAP's build/openldap.m4 and some 19*a6f3f22fSchristosdnl fragments of OpenLDAP's configure.ac . 20*a6f3f22fSchristos 21b5bbe2e3Schristos# OL_THREAD_CHECK([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) 22b5bbe2e3Schristos 23b5bbe2e3SchristosAC_DEFUN([OL_THREAD_CHECK], [ 24b5bbe2e3SchristosAC_REQUIRE([AC_CANONICAL_HOST]) 25b5bbe2e3SchristosAC_LANG_SAVE 26b5bbe2e3SchristosAC_LANG([C]) 27b5bbe2e3SchristosOL_ARG_WITH(threads,[ --with-threads with threads], 28b5bbe2e3Schristos auto, [auto nt posix mach pth lwp yes no manual] ) 29b5bbe2e3Schristos 30b5bbe2e3Schristoscase "$ol_with_threads$host" in 31b5bbe2e3Schristos auto*-*-solaris2.[[0-6]]) 32b5bbe2e3Schristos dnl signals sometimes delivered to wrong thread with Solaris 2.6 33b5bbe2e3Schristos ol_with_threads=no 34b5bbe2e3Schristos ;; 35b5bbe2e3Schristosesac 36b5bbe2e3Schristos 37b5bbe2e3Schristosdnl AIX Thread requires we use cc_r or xlc_r. 38b5bbe2e3Schristosdnl But only do this IF AIX and CC is not set 39b5bbe2e3Schristosdnl and threads are auto|yes|posix. 40b5bbe2e3Schristosdnl 41b5bbe2e3Schristosdnl If we find cc_r|xlc_r, force pthreads and assume 42b5bbe2e3Schristosdnl pthread_create is in $LIBS (ie: don't bring in 43b5bbe2e3Schristosdnl any additional thread libraries) 44b5bbe2e3Schristosdnl If we do not find cc_r|xlc_r, disable threads 45b5bbe2e3Schristos 46b5bbe2e3Schristosol_aix_threads=no 47b5bbe2e3Schristoscase "$host" in 48b5bbe2e3Schristos*-*-aix*) dnl all AIX is not a good idea. 49b5bbe2e3Schristos if test -z "$CC" ; then 50b5bbe2e3Schristos case "$ol_with_threads" in 51b5bbe2e3Schristos auto | yes | posix) ol_aix_threads=yes ;; 52b5bbe2e3Schristos esac 53b5bbe2e3Schristos fi 54b5bbe2e3Schristos;; 55b5bbe2e3Schristosesac 56b5bbe2e3Schristos 57b5bbe2e3Schristosif test $ol_aix_threads = yes ; then 58b5bbe2e3Schristos if test -z "${CC}" ; then 59b5bbe2e3Schristos AC_CHECK_PROGS(CC,cc_r xlc_r cc) 60b5bbe2e3Schristos 61b5bbe2e3Schristos if test "$CC" = cc ; then 62b5bbe2e3Schristos dnl no CC! don't allow --with-threads 63b5bbe2e3Schristos if test $ol_with_threads != auto ; then 64b5bbe2e3Schristos AC_MSG_ERROR([--with-threads requires cc_r (or other suitable compiler) on AIX]) 65b5bbe2e3Schristos else 66b5bbe2e3Schristos AC_MSG_WARN([disabling threads, no cc_r on AIX]) 67b5bbe2e3Schristos fi 68b5bbe2e3Schristos ol_with_threads=no 69b5bbe2e3Schristos fi 70b5bbe2e3Schristos fi 71b5bbe2e3Schristos 72b5bbe2e3Schristos case ${CC} in cc_r | xlc_r) 73b5bbe2e3Schristos ol_with_threads=posix 74b5bbe2e3Schristos ol_cv_pthread_create=yes 75b5bbe2e3Schristos ;; 76b5bbe2e3Schristos esac 77b5bbe2e3Schristosfi 78b5bbe2e3Schristos 79b5bbe2e3Schristosdnl ---------------------------------------------------------------- 80b5bbe2e3Schristosdnl Threads? 81b5bbe2e3Schristosol_link_threads=no 82b5bbe2e3Schristosdnl ol_with_yielding_select=${ol_with_yielding_select:-auto} 83b5bbe2e3SchristosOL_ARG_WITH(yielding_select,[ --with-yielding-select with yielding select], 84b5bbe2e3Schristos auto, [auto yes no manual] ) 85b5bbe2e3Schristos 86b5bbe2e3Schristoscase $ol_with_threads in auto | yes | nt) 87b5bbe2e3Schristos 88b5bbe2e3Schristos OL_NT_THREADS 89b5bbe2e3Schristos 90b5bbe2e3Schristos if test "$ol_cv_nt_threads" = yes ; then 91b5bbe2e3Schristos ol_link_threads=nt 92b5bbe2e3Schristos ol_with_threads=found 93b5bbe2e3Schristos ol_with_yielding_select=yes 94b5bbe2e3Schristos 95b5bbe2e3Schristos AC_DEFINE([HAVE_NT_SERVICE_MANAGER], [1], [if you have NT Service Manager]) 96b5bbe2e3Schristos AC_DEFINE([HAVE_NT_EVENT_LOG], [1], [if you have NT Event Log]) 97b5bbe2e3Schristos fi 98b5bbe2e3Schristos 99b5bbe2e3Schristos if test $ol_with_threads = nt ; then 100b5bbe2e3Schristos AC_MSG_ERROR([could not locate NT Threads]) 101b5bbe2e3Schristos fi 102b5bbe2e3Schristos ;; 103b5bbe2e3Schristosesac 104b5bbe2e3Schristos 105b5bbe2e3Schristoscase $ol_with_threads in auto | yes | posix) 106b5bbe2e3Schristos 107b5bbe2e3Schristos AC_CHECK_HEADERS(pthread.h) 108b5bbe2e3Schristos 109b5bbe2e3Schristos if test $ac_cv_header_pthread_h = yes ; then 110b5bbe2e3Schristos OL_POSIX_THREAD_VERSION 111b5bbe2e3Schristos 112b5bbe2e3Schristos if test $ol_cv_pthread_version != 0 ; then 113b5bbe2e3Schristos AC_DEFINE_UNQUOTED([HAVE_PTHREADS], [$ol_cv_pthread_version], 114b5bbe2e3Schristos [define to pthreads API spec revision]) 115b5bbe2e3Schristos else 116b5bbe2e3Schristos AC_MSG_ERROR([unknown pthread version]) 117b5bbe2e3Schristos fi 118b5bbe2e3Schristos 119b5bbe2e3Schristos # consider threads found 120b5bbe2e3Schristos ol_with_threads=found 121b5bbe2e3Schristos 122b5bbe2e3Schristos OL_HEADER_LINUX_THREADS 123b5bbe2e3Schristos OL_HEADER_GNU_PTH_PTHREAD_H 124b5bbe2e3Schristos 125b5bbe2e3Schristos if test $ol_cv_header_gnu_pth_pthread_h = no ; then 126b5bbe2e3Schristos AC_CHECK_HEADERS(sched.h) 127b5bbe2e3Schristos fi 128b5bbe2e3Schristos 129b5bbe2e3Schristos dnl Now the hard part, how to link? 130b5bbe2e3Schristos dnl 131b5bbe2e3Schristos dnl currently supported checks: 132b5bbe2e3Schristos dnl 133b5bbe2e3Schristos dnl Check for no flags 134b5bbe2e3Schristos dnl pthread_create() in $LIBS 135b5bbe2e3Schristos dnl 136b5bbe2e3Schristos dnl Check special pthread (final) flags 137b5bbe2e3Schristos dnl [skipped] pthread_create() with -mt (Solaris) [disabled] 138b5bbe2e3Schristos dnl pthread_create() with -kthread (FreeBSD) 139b5bbe2e3Schristos dnl pthread_create() with -pthread (FreeBSD/Digital Unix) 140b5bbe2e3Schristos dnl pthread_create() with -pthreads (?) 141b5bbe2e3Schristos dnl pthread_create() with -mthreads (AIX) 142b5bbe2e3Schristos dnl pthread_create() with -thread (?) 143b5bbe2e3Schristos dnl 144b5bbe2e3Schristos dnl Check pthread (final) libraries 145b5bbe2e3Schristos dnl pthread_mutex_unlock() in -lpthread -lmach -lexc -lc_r (OSF/1) 146b5bbe2e3Schristos dnl pthread_mutex_lock() in -lpthread -lmach -lexc (OSF/1) 147b5bbe2e3Schristos dnl [skipped] pthread_mutex_trylock() in -lpthread -lexc (OSF/1) 148b5bbe2e3Schristos dnl pthread_join() -Wl,-woff,85 -lpthread (IRIX) 149b5bbe2e3Schristos dnl pthread_create() in -lpthread (many) 150b5bbe2e3Schristos dnl pthread_create() in -lc_r (FreeBSD) 151b5bbe2e3Schristos dnl 152b5bbe2e3Schristos dnl Check pthread (draft4) flags (depreciated) 153b5bbe2e3Schristos dnl pthread_create() with -threads (OSF/1) 154b5bbe2e3Schristos dnl 155b5bbe2e3Schristos dnl Check pthread (draft4) libraries (depreciated) 156b5bbe2e3Schristos dnl pthread_mutex_unlock() in -lpthreads -lmach -lexc -lc_r (OSF/1) 157b5bbe2e3Schristos dnl pthread_mutex_lock() in -lpthreads -lmach -lexc (OSF/1) 158b5bbe2e3Schristos dnl pthread_mutex_trylock() in -lpthreads -lexc (OSF/1) 159b5bbe2e3Schristos dnl pthread_create() in -lpthreads (many) 160b5bbe2e3Schristos dnl 161b5bbe2e3Schristos 162b5bbe2e3Schristos dnl pthread_create in $LIBS 163b5bbe2e3Schristos AC_CACHE_CHECK([for pthread_create in default libraries], 164b5bbe2e3Schristos ol_cv_pthread_create,[ 165b5bbe2e3Schristos AC_RUN_IFELSE([OL_PTHREAD_TEST_PROGRAM], 166b5bbe2e3Schristos [ol_cv_pthread_create=yes], 167b5bbe2e3Schristos [ol_cv_pthread_create=no], 168b5bbe2e3Schristos [AC_TRY_LINK(OL_PTHREAD_TEST_INCLUDES,OL_PTHREAD_TEST_FUNCTION, 169b5bbe2e3Schristos [ol_cv_pthread_create=yes], 170b5bbe2e3Schristos [ol_cv_pthread_create=no])])]) 171b5bbe2e3Schristos 172b5bbe2e3Schristos if test $ol_cv_pthread_create != no ; then 173b5bbe2e3Schristos ol_link_threads=posix 174b5bbe2e3Schristos ol_link_pthreads="" 175b5bbe2e3Schristos fi 176b5bbe2e3Schristos 177b5bbe2e3Schristosdnl OL_PTHREAD_TRY([-mt], [ol_cv_pthread_mt]) 178b5bbe2e3Schristos OL_PTHREAD_TRY([-kthread], [ol_cv_pthread_kthread]) 179b5bbe2e3Schristos OL_PTHREAD_TRY([-pthread], [ol_cv_pthread_pthread]) 180b5bbe2e3Schristos OL_PTHREAD_TRY([-pthreads], [ol_cv_pthread_pthreads]) 181b5bbe2e3Schristos OL_PTHREAD_TRY([-mthreads], [ol_cv_pthread_mthreads]) 182b5bbe2e3Schristos OL_PTHREAD_TRY([-thread], [ol_cv_pthread_thread]) 183b5bbe2e3Schristos 184b5bbe2e3Schristos OL_PTHREAD_TRY([-lpthread -lmach -lexc -lc_r], 185b5bbe2e3Schristos [ol_cv_pthread_lpthread_lmach_lexc_lc_r]) 186b5bbe2e3Schristos OL_PTHREAD_TRY([-lpthread -lmach -lexc], 187b5bbe2e3Schristos [ol_cv_pthread_lpthread_lmach_lexc]) 188b5bbe2e3Schristosdnl OL_PTHREAD_TRY([-lpthread -lexc], 189b5bbe2e3Schristosdnl [ol_cv_pthread_lpthread_lexc]) 190b5bbe2e3Schristos 191b5bbe2e3Schristos OL_PTHREAD_TRY([-lpthread -Wl,-woff,85], 192b5bbe2e3Schristos [ol_cv_pthread_lib_lpthread_woff]) 193b5bbe2e3Schristos 194b5bbe2e3Schristos OL_PTHREAD_TRY([-lpthread], [ol_cv_pthread_lpthread]) 195b5bbe2e3Schristos OL_PTHREAD_TRY([-lc_r], [ol_cv_pthread_lc_r]) 196b5bbe2e3Schristos 197b5bbe2e3Schristos OL_PTHREAD_TRY([-threads], [ol_cv_pthread_threads]) 198b5bbe2e3Schristos 199b5bbe2e3Schristos OL_PTHREAD_TRY([-lpthreads -lmach -lexc -lc_r], 200b5bbe2e3Schristos [ol_cv_pthread_lpthreads_lmach_lexc_lc_r]) 201b5bbe2e3Schristos OL_PTHREAD_TRY([-lpthreads -lmach -lexc], 202b5bbe2e3Schristos [ol_cv_pthread_lpthreads_lmach_lexc]) 203b5bbe2e3Schristos OL_PTHREAD_TRY([-lpthreads -lexc], 204b5bbe2e3Schristos [ol_cv_pthread_lpthreads_lexc]) 205b5bbe2e3Schristos 206b5bbe2e3Schristos OL_PTHREAD_TRY([-lpthreads],[ol_cv_pthread_lib_lpthreads]) 207b5bbe2e3Schristos 208*a6f3f22fSchristosAC_MSG_NOTICE([ol_link_threads: <$ol_link_threads> ol_link_pthreads <$ol_link_pthreads>]) 209*a6f3f22fSchristos 210b5bbe2e3Schristos if test $ol_link_threads != no ; then 211b5bbe2e3Schristos LTHREAD_LIBS="$LTHREAD_LIBS $ol_link_pthreads" 212b5bbe2e3Schristos 213b5bbe2e3Schristos dnl save flags 214b5bbe2e3Schristos save_CPPFLAGS="$CPPFLAGS" 215b5bbe2e3Schristos save_LIBS="$LIBS" 216b5bbe2e3Schristos LIBS="$LTHREAD_LIBS $LIBS" 217b5bbe2e3Schristos 218b5bbe2e3Schristos dnl All POSIX Thread (final) implementations should have 219b5bbe2e3Schristos dnl sched_yield instead of pthread yield. 220b5bbe2e3Schristos dnl check for both, and thr_yield for Solaris 221b5bbe2e3Schristos AC_CHECK_FUNCS(sched_yield pthread_yield thr_yield) 222b5bbe2e3Schristos 223b5bbe2e3Schristos if test $ac_cv_func_sched_yield = no && 224b5bbe2e3Schristos test $ac_cv_func_pthread_yield = no && 225b5bbe2e3Schristos test $ac_cv_func_thr_yield = no ; then 226b5bbe2e3Schristos dnl Digital UNIX has sched_yield() in -lrt 227b5bbe2e3Schristos AC_CHECK_LIB(rt, sched_yield, 228b5bbe2e3Schristos [LTHREAD_LIBS="$LTHREAD_LIBS -lrt" 229b5bbe2e3Schristos AC_DEFINE([HAVE_SCHED_YIELD], [1], 230b5bbe2e3Schristos [Define if you have the sched_yield function.]) 231b5bbe2e3Schristos ac_cv_func_sched_yield=yes], 232b5bbe2e3Schristos [ac_cv_func_sched_yield=no]) 233b5bbe2e3Schristos fi 234b5bbe2e3Schristos if test $ac_cv_func_sched_yield = no && 235b5bbe2e3Schristos test $ac_cv_func_pthread_yield = no && 236b5bbe2e3Schristos test "$ac_cv_func_thr_yield" = no ; then 237b5bbe2e3Schristos AC_MSG_WARN([could not locate sched_yield() or pthread_yield()]) 238b5bbe2e3Schristos fi 239b5bbe2e3Schristos 240b5bbe2e3Schristos dnl Check functions for compatibility 241b5bbe2e3Schristos AC_CHECK_FUNCS(pthread_kill) 242b5bbe2e3Schristos 243b5bbe2e3Schristos dnl Check for pthread_rwlock_destroy with <pthread.h> 244b5bbe2e3Schristos dnl as pthread_rwlock_t may not be defined. 245b5bbe2e3Schristos AC_CACHE_CHECK([for pthread_rwlock_destroy with <pthread.h>], 246b5bbe2e3Schristos [ol_cv_func_pthread_rwlock_destroy], [ 247b5bbe2e3Schristos dnl save the flags 248b5bbe2e3Schristos AC_LINK_IFELSE([AC_LANG_PROGRAM([[ 249b5bbe2e3Schristos#include <pthread.h> 250b5bbe2e3Schristospthread_rwlock_t rwlock; 251b5bbe2e3Schristos]], [[pthread_rwlock_destroy(&rwlock);]])],[ol_cv_func_pthread_rwlock_destroy=yes],[ol_cv_func_pthread_rwlock_destroy=no]) 252b5bbe2e3Schristos ]) 253b5bbe2e3Schristos if test $ol_cv_func_pthread_rwlock_destroy = yes ; then 254b5bbe2e3Schristos AC_DEFINE([HAVE_PTHREAD_RWLOCK_DESTROY], [1], 255b5bbe2e3Schristos [define if you have pthread_rwlock_destroy function]) 256b5bbe2e3Schristos fi 257b5bbe2e3Schristos 258b5bbe2e3Schristos dnl Check for pthread_detach with <pthread.h> inclusion 259b5bbe2e3Schristos dnl as it's symbol may have been mangled. 260b5bbe2e3Schristos AC_CACHE_CHECK([for pthread_detach with <pthread.h>], 261b5bbe2e3Schristos [ol_cv_func_pthread_detach], [ 262b5bbe2e3Schristos dnl save the flags 263b5bbe2e3Schristos AC_LINK_IFELSE([AC_LANG_PROGRAM([[ 264b5bbe2e3Schristos#include <pthread.h> 265b5bbe2e3Schristos#ifndef NULL 266b5bbe2e3Schristos#define NULL (void*)0 267b5bbe2e3Schristos#endif 268b5bbe2e3Schristos]], [[pthread_detach(NULL);]])],[ol_cv_func_pthread_detach=yes],[ol_cv_func_pthread_detach=no]) 269b5bbe2e3Schristos ]) 270b5bbe2e3Schristos 271b5bbe2e3Schristos if test $ol_cv_func_pthread_detach = no ; then 272b5bbe2e3Schristos AC_MSG_ERROR([could not locate pthread_detach()]) 273b5bbe2e3Schristos fi 274b5bbe2e3Schristos 275b5bbe2e3Schristos AC_DEFINE([HAVE_PTHREAD_DETACH], [1], 276b5bbe2e3Schristos [define if you have pthread_detach function]) 277b5bbe2e3Schristos 278b5bbe2e3Schristos dnl Check for setconcurreny functions 279b5bbe2e3Schristos AC_CHECK_FUNCS( \ 280b5bbe2e3Schristos pthread_setconcurrency \ 281b5bbe2e3Schristos pthread_getconcurrency \ 282b5bbe2e3Schristos thr_setconcurrency \ 283b5bbe2e3Schristos thr_getconcurrency \ 284b5bbe2e3Schristos ) 285b5bbe2e3Schristos 286b5bbe2e3Schristos OL_SYS_LINUX_THREADS 287b5bbe2e3Schristos OL_LINUX_THREADS 288b5bbe2e3Schristos 289b5bbe2e3Schristos if test $ol_cv_linux_threads = error; then 290b5bbe2e3Schristos AC_MSG_ERROR([LinuxThreads header/library mismatch]); 291b5bbe2e3Schristos fi 292b5bbe2e3Schristos 293b5bbe2e3Schristos AC_CACHE_CHECK([if pthread_create() works], 294b5bbe2e3Schristos ol_cv_pthread_create_works,[ 295b5bbe2e3Schristos AC_RUN_IFELSE([OL_PTHREAD_TEST_PROGRAM], 296b5bbe2e3Schristos [ol_cv_pthread_create_works=yes], 297b5bbe2e3Schristos [ol_cv_pthread_create_works=no], 298b5bbe2e3Schristos [dnl assume yes 299b5bbe2e3Schristos ol_cv_pthread_create_works=yes])]) 300b5bbe2e3Schristos 301b5bbe2e3Schristos if test $ol_cv_pthread_create_works = no ; then 302b5bbe2e3Schristos AC_MSG_ERROR([pthread_create is not usable, check environment settings]) 303b5bbe2e3Schristos fi 304b5bbe2e3Schristos 305b5bbe2e3Schristos ol_replace_broken_yield=no 306b5bbe2e3Schristosdnl case "$host" in 307b5bbe2e3Schristosdnl *-*-linux*) 308b5bbe2e3Schristosdnl AC_CHECK_FUNCS(nanosleep) 309b5bbe2e3Schristosdnl ol_replace_broken_yield=yes 310b5bbe2e3Schristosdnl ;; 311b5bbe2e3Schristosdnl esac 312b5bbe2e3Schristos 313b5bbe2e3Schristos if test $ol_replace_broken_yield = yes ; then 314b5bbe2e3Schristos AC_DEFINE([REPLACE_BROKEN_YIELD], [1], 315b5bbe2e3Schristos [define if sched_yield yields the entire process]) 316b5bbe2e3Schristos fi 317b5bbe2e3Schristos 318b5bbe2e3Schristos dnl Check if select causes an yield 319b5bbe2e3Schristos if test x$ol_with_yielding_select = xauto ; then 320b5bbe2e3Schristos AC_CACHE_CHECK([if select yields when using pthreads], 321b5bbe2e3Schristos ol_cv_pthread_select_yields,[ 322b5bbe2e3Schristos AC_RUN_IFELSE([AC_LANG_SOURCE([[ 323b5bbe2e3Schristos#include <sys/types.h> 324b5bbe2e3Schristos#include <sys/time.h> 325b5bbe2e3Schristos#include <unistd.h> 326b5bbe2e3Schristos#include <pthread.h> 327b5bbe2e3Schristos#ifndef NULL 328b5bbe2e3Schristos#define NULL (void*) 0 329b5bbe2e3Schristos#endif 330b5bbe2e3Schristos 331b5bbe2e3Schristosstatic int fildes[2]; 332b5bbe2e3Schristos 333b5bbe2e3Schristosstatic void *task(p) 334b5bbe2e3Schristos void *p; 335b5bbe2e3Schristos{ 336b5bbe2e3Schristos int i; 337b5bbe2e3Schristos struct timeval tv; 338b5bbe2e3Schristos 339b5bbe2e3Schristos fd_set rfds; 340b5bbe2e3Schristos 341b5bbe2e3Schristos tv.tv_sec=10; 342b5bbe2e3Schristos tv.tv_usec=0; 343b5bbe2e3Schristos 344b5bbe2e3Schristos FD_ZERO(&rfds); 345b5bbe2e3Schristos FD_SET(fildes[0], &rfds); 346b5bbe2e3Schristos 347b5bbe2e3Schristos /* we're not interested in any fds */ 348b5bbe2e3Schristos i = select(FD_SETSIZE, &rfds, NULL, NULL, &tv); 349b5bbe2e3Schristos 350b5bbe2e3Schristos if(i < 0) { 351b5bbe2e3Schristos perror("select"); 352b5bbe2e3Schristos exit(10); 353b5bbe2e3Schristos } 354b5bbe2e3Schristos 355b5bbe2e3Schristos exit(0); /* if we exit here, the select blocked the whole process */ 356b5bbe2e3Schristos} 357b5bbe2e3Schristos 358b5bbe2e3Schristosint main(argc, argv) 359b5bbe2e3Schristos int argc; 360b5bbe2e3Schristos char **argv; 361b5bbe2e3Schristos{ 362b5bbe2e3Schristos pthread_t t; 363b5bbe2e3Schristos 364b5bbe2e3Schristos /* create a pipe to select */ 365b5bbe2e3Schristos if(pipe(&fildes[0])) { 366b5bbe2e3Schristos perror("select"); 367b5bbe2e3Schristos exit(1); 368b5bbe2e3Schristos } 369b5bbe2e3Schristos 370b5bbe2e3Schristos#ifdef HAVE_PTHREAD_SETCONCURRENCY 371b5bbe2e3Schristos (void) pthread_setconcurrency(2); 372b5bbe2e3Schristos#else 373b5bbe2e3Schristos#ifdef HAVE_THR_SETCONCURRENCY 374b5bbe2e3Schristos /* Set Solaris LWP concurrency to 2 */ 375b5bbe2e3Schristos thr_setconcurrency(2); 376b5bbe2e3Schristos#endif 377b5bbe2e3Schristos#endif 378b5bbe2e3Schristos 379b5bbe2e3Schristos#if HAVE_PTHREADS < 6 380b5bbe2e3Schristos pthread_create(&t, pthread_attr_default, task, NULL); 381b5bbe2e3Schristos#else 382b5bbe2e3Schristos pthread_create(&t, NULL, task, NULL); 383b5bbe2e3Schristos#endif 384b5bbe2e3Schristos 385b5bbe2e3Schristos /* make sure task runs first */ 386b5bbe2e3Schristos#ifdef HAVE_THR_YIELD 387b5bbe2e3Schristos thr_yield(); 388b5bbe2e3Schristos#elif defined( HAVE_SCHED_YIELD ) 389b5bbe2e3Schristos sched_yield(); 390b5bbe2e3Schristos#elif defined( HAVE_PTHREAD_YIELD ) 391b5bbe2e3Schristos pthread_yield(); 392b5bbe2e3Schristos#endif 393b5bbe2e3Schristos 394b5bbe2e3Schristos exit(2); 395b5bbe2e3Schristos}]])],[ol_cv_pthread_select_yields=no],[ol_cv_pthread_select_yields=yes],[ol_cv_pthread_select_yields=cross])]) 396b5bbe2e3Schristos 397b5bbe2e3Schristos if test $ol_cv_pthread_select_yields = cross ; then 398b5bbe2e3Schristos AC_MSG_ERROR([crossing compiling: use --with-yielding-select=yes|no|manual]) 399b5bbe2e3Schristos fi 400b5bbe2e3Schristos 401b5bbe2e3Schristos if test $ol_cv_pthread_select_yields = yes ; then 402b5bbe2e3Schristos ol_with_yielding_select=yes 403b5bbe2e3Schristos fi 404b5bbe2e3Schristos fi 405b5bbe2e3Schristos 406b5bbe2e3Schristos dnl restore flags 407b5bbe2e3Schristos CPPFLAGS="$save_CPPFLAGS" 408b5bbe2e3Schristos LIBS="$save_LIBS" 409b5bbe2e3Schristos else 410b5bbe2e3Schristos AC_MSG_ERROR([could not locate usable POSIX Threads]) 411b5bbe2e3Schristos fi 412b5bbe2e3Schristos fi 413b5bbe2e3Schristos 414b5bbe2e3Schristos if test $ol_with_threads = posix ; then 415b5bbe2e3Schristos AC_MSG_ERROR([could not locate POSIX Threads]) 416b5bbe2e3Schristos fi 417b5bbe2e3Schristos ;; 418b5bbe2e3Schristosesac 419b5bbe2e3Schristos 420b5bbe2e3Schristoscase $ol_with_threads in auto | yes | mach) 421b5bbe2e3Schristos 422b5bbe2e3Schristos dnl check for Mach CThreads 423b5bbe2e3Schristos AC_CHECK_HEADERS(mach/cthreads.h cthreads.h) 424b5bbe2e3Schristos if test $ac_cv_header_mach_cthreads_h = yes ; then 425b5bbe2e3Schristos ol_with_threads=found 426b5bbe2e3Schristos 427b5bbe2e3Schristos dnl check for cthreads support in current $LIBS 428b5bbe2e3Schristos AC_CHECK_FUNC(cthread_fork,[ol_link_threads=yes]) 429b5bbe2e3Schristos 430b5bbe2e3Schristos if test $ol_link_threads = no ; then 431b5bbe2e3Schristos dnl try -all_load 432b5bbe2e3Schristos dnl this test needs work 433b5bbe2e3Schristos AC_CACHE_CHECK([for cthread_fork with -all_load], 434b5bbe2e3Schristos [ol_cv_cthread_all_load], [ 435b5bbe2e3Schristos dnl save the flags 436b5bbe2e3Schristos save_LIBS="$LIBS" 437b5bbe2e3Schristos LIBS="-all_load $LIBS" 438b5bbe2e3Schristos AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <mach/cthreads.h>]], [[ 439b5bbe2e3Schristos cthread_fork((void *)0, (void *)0); 440b5bbe2e3Schristos ]])],[ol_cv_cthread_all_load=yes],[ol_cv_cthread_all_load=no]) 441b5bbe2e3Schristos dnl restore the LIBS 442b5bbe2e3Schristos LIBS="$save_LIBS" 443b5bbe2e3Schristos ]) 444b5bbe2e3Schristos 445b5bbe2e3Schristos if test $ol_cv_cthread_all_load = yes ; then 446b5bbe2e3Schristos LTHREAD_LIBS="$LTHREAD_LIBS -all_load" 447b5bbe2e3Schristos ol_link_threads=mach 448b5bbe2e3Schristos ol_with_threads=found 449b5bbe2e3Schristos fi 450b5bbe2e3Schristos fi 451b5bbe2e3Schristos 452b5bbe2e3Schristos elif test $ac_cv_header_cthreads_h = yes ; then 453b5bbe2e3Schristos dnl Hurd variant of Mach Cthreads 454b5bbe2e3Schristos dnl uses <cthreads.h> and -lthreads 455b5bbe2e3Schristos 456b5bbe2e3Schristos ol_with_threads=found 457b5bbe2e3Schristos 458b5bbe2e3Schristos dnl save the flags 459b5bbe2e3Schristos save_LIBS="$LIBS" 460b5bbe2e3Schristos LIBS="$LIBS -lthreads" 461b5bbe2e3Schristos AC_CHECK_FUNC(cthread_fork,[ol_link_threads=yes]) 462b5bbe2e3Schristos LIBS="$save_LIBS" 463b5bbe2e3Schristos 464b5bbe2e3Schristos if test $ol_link_threads = yes ; then 465b5bbe2e3Schristos LTHREAD_LIBS="-lthreads" 466b5bbe2e3Schristos ol_link_threads=mach 467b5bbe2e3Schristos ol_with_threads=found 468b5bbe2e3Schristos else 469b5bbe2e3Schristos AC_MSG_ERROR([could not link with Mach CThreads]) 470b5bbe2e3Schristos fi 471b5bbe2e3Schristos 472b5bbe2e3Schristos elif test $ol_with_threads = mach ; then 473b5bbe2e3Schristos AC_MSG_ERROR([could not locate Mach CThreads]) 474b5bbe2e3Schristos fi 475b5bbe2e3Schristos 476b5bbe2e3Schristos if test $ol_link_threads = mach ; then 477b5bbe2e3Schristos AC_DEFINE([HAVE_MACH_CTHREADS], [1], 478b5bbe2e3Schristos [define if you have Mach Cthreads]) 479b5bbe2e3Schristos elif test $ol_with_threads = found ; then 480b5bbe2e3Schristos AC_MSG_ERROR([could not link with Mach CThreads]) 481b5bbe2e3Schristos fi 482b5bbe2e3Schristos ;; 483b5bbe2e3Schristosesac 484b5bbe2e3Schristos 485b5bbe2e3Schristoscase $ol_with_threads in auto | yes | pth) 486b5bbe2e3Schristos 487b5bbe2e3Schristos AC_CHECK_HEADERS(pth.h) 488b5bbe2e3Schristos 489b5bbe2e3Schristos if test $ac_cv_header_pth_h = yes ; then 490b5bbe2e3Schristos AC_CHECK_LIB(pth, pth_version, [have_pth=yes], [have_pth=no]) 491b5bbe2e3Schristos 492b5bbe2e3Schristos if test $have_pth = yes ; then 493b5bbe2e3Schristos AC_DEFINE([HAVE_GNU_PTH], [1], [if you have GNU Pth]) 494b5bbe2e3Schristos LTHREAD_LIBS="$LTHREAD_LIBS -lpth" 495b5bbe2e3Schristos ol_link_threads=pth 496b5bbe2e3Schristos ol_with_threads=found 497b5bbe2e3Schristos 498b5bbe2e3Schristos if test x$ol_with_yielding_select = xauto ; then 499b5bbe2e3Schristos ol_with_yielding_select=yes 500b5bbe2e3Schristos fi 501b5bbe2e3Schristos fi 502b5bbe2e3Schristos fi 503b5bbe2e3Schristos ;; 504b5bbe2e3Schristosesac 505b5bbe2e3Schristos 506b5bbe2e3Schristoscase $ol_with_threads in auto | yes | lwp) 507b5bbe2e3Schristos 508b5bbe2e3Schristos dnl check for SunOS5 LWP 509b5bbe2e3Schristos AC_CHECK_HEADERS(thread.h synch.h) 510b5bbe2e3Schristos if test $ac_cv_header_thread_h = yes && 511b5bbe2e3Schristos test $ac_cv_header_synch_h = yes ; then 512b5bbe2e3Schristos AC_CHECK_LIB(thread, thr_create, [have_thr=yes], [have_thr=no]) 513b5bbe2e3Schristos 514b5bbe2e3Schristos if test $have_thr = yes ; then 515b5bbe2e3Schristos AC_DEFINE([HAVE_THR], [1], 516b5bbe2e3Schristos [if you have Solaris LWP (thr) package]) 517b5bbe2e3Schristos LTHREAD_LIBS="$LTHREAD_LIBS -lthread" 518b5bbe2e3Schristos ol_link_threads=thr 519b5bbe2e3Schristos 520b5bbe2e3Schristos if test x$ol_with_yielding_select = xauto ; then 521b5bbe2e3Schristos ol_with_yielding_select=yes 522b5bbe2e3Schristos fi 523b5bbe2e3Schristos 524b5bbe2e3Schristos dnl Check for setconcurrency functions 525b5bbe2e3Schristos AC_CHECK_FUNCS( \ 526b5bbe2e3Schristos thr_setconcurrency \ 527b5bbe2e3Schristos thr_getconcurrency \ 528b5bbe2e3Schristos ) 529b5bbe2e3Schristos fi 530b5bbe2e3Schristos fi 531b5bbe2e3Schristos 532b5bbe2e3Schristos dnl check for SunOS4 LWP 533b5bbe2e3Schristos AC_CHECK_HEADERS(lwp/lwp.h) 534b5bbe2e3Schristos if test $ac_cv_header_lwp_lwp_h = yes ; then 535b5bbe2e3Schristos AC_CHECK_LIB(lwp, lwp_create, [have_lwp=yes], [have_lwp=no]) 536b5bbe2e3Schristos 537b5bbe2e3Schristos if test $have_lwp = yes ; then 538b5bbe2e3Schristos AC_DEFINE([HAVE_LWP], [1], 539b5bbe2e3Schristos [if you have SunOS LWP package]) 540b5bbe2e3Schristos LTHREAD_LIBS="$LTHREAD_LIBS -llwp" 541b5bbe2e3Schristos ol_link_threads=lwp 542b5bbe2e3Schristos 543b5bbe2e3Schristos if test x$ol_with_yielding_select = xauto ; then 544b5bbe2e3Schristos ol_with_yielding_select=no 545b5bbe2e3Schristos fi 546b5bbe2e3Schristos fi 547b5bbe2e3Schristos fi 548b5bbe2e3Schristos ;; 549b5bbe2e3Schristosesac 550b5bbe2e3Schristos 551b5bbe2e3Schristosif test $ol_with_yielding_select = yes ; then 552b5bbe2e3Schristos AC_DEFINE([HAVE_YIELDING_SELECT], [1], 553b5bbe2e3Schristos [define if select implicitly yields]) 554b5bbe2e3Schristosfi 555b5bbe2e3Schristos 556b5bbe2e3Schristosif test $ol_with_threads = manual ; then 557b5bbe2e3Schristos dnl User thinks he can manually configure threads. 558b5bbe2e3Schristos ol_link_threads=yes 559b5bbe2e3Schristos 560b5bbe2e3Schristos AC_MSG_WARN([thread defines and link options must be set manually]) 561b5bbe2e3Schristos 562b5bbe2e3Schristos AC_CHECK_HEADERS(pthread.h sched.h) 563b5bbe2e3Schristos AC_CHECK_FUNCS(sched_yield pthread_yield) 564b5bbe2e3Schristos OL_HEADER_LINUX_THREADS 565b5bbe2e3Schristos 566b5bbe2e3Schristos AC_CHECK_HEADERS(mach/cthreads.h) 567b5bbe2e3Schristos AC_CHECK_HEADERS(lwp/lwp.h) 568b5bbe2e3Schristos AC_CHECK_HEADERS(thread.h synch.h) 569b5bbe2e3Schristosfi 570b5bbe2e3Schristos 571b5bbe2e3Schristosif test $ol_link_threads != no && test $ol_link_threads != nt ; then 572b5bbe2e3Schristos dnl needed to get reentrant/threadsafe versions 573b5bbe2e3Schristos dnl 574b5bbe2e3Schristos AC_DEFINE([REENTRANT], [1], [enable thread safety]) 575b5bbe2e3Schristos AC_DEFINE([_REENTRANT], [1], [enable thread safety]) 576b5bbe2e3Schristos AC_DEFINE([THREAD_SAFE], [1], [enable thread safety]) 577b5bbe2e3Schristos AC_DEFINE([_THREAD_SAFE], [1], [enable thread safety]) 578b5bbe2e3Schristos AC_DEFINE([THREADSAFE], [1], [enable thread safety]) 579b5bbe2e3Schristos AC_DEFINE([_THREADSAFE], [1], [enable thread safety]) 580b5bbe2e3Schristos AC_DEFINE([_SGI_MP_SOURCE], [1], [enable thread safety]) 581b5bbe2e3Schristos 582b5bbe2e3Schristos dnl The errno declaration may dependent upon _REENTRANT. 583b5bbe2e3Schristos dnl If it does, we must link with thread support. 584b5bbe2e3Schristos AC_CACHE_CHECK([for thread specific errno], 585b5bbe2e3Schristos [ol_cv_errno_thread_specific], [ 586b5bbe2e3Schristos AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <errno.h>]], [[errno = 0;]])],[ol_cv_errno_thread_specific=yes],[ol_cv_errno_thread_specific=no]) 587b5bbe2e3Schristos ]) 588b5bbe2e3Schristos 589b5bbe2e3Schristos dnl The h_errno declaration may dependent upon _REENTRANT. 590b5bbe2e3Schristos dnl If it does, we must link with thread support. 591b5bbe2e3Schristos AC_CACHE_CHECK([for thread specific h_errno], 592b5bbe2e3Schristos [ol_cv_h_errno_thread_specific], [ 593b5bbe2e3Schristos AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <netdb.h>]], [[h_errno = 0;]])],[ol_cv_h_errno_thread_specific=yes],[ol_cv_h_errno_thread_specific=no]) 594b5bbe2e3Schristos ]) 595b5bbe2e3Schristos 596b5bbe2e3Schristos if test $ol_cv_errno_thread_specific != yes || 597b5bbe2e3Schristos test $ol_cv_h_errno_thread_specific != yes ; then 598b5bbe2e3Schristos LIBS="$LTHREAD_LIBS $LIBS" 599b5bbe2e3Schristos LTHREAD_LIBS="" 600b5bbe2e3Schristos fi 601b5bbe2e3Schristos 602b5bbe2e3Schristosdnl When in thread environment, use 603b5bbe2e3Schristosdnl #if defined( HAVE_REENTRANT_FUNCTIONS ) || defined( HAVE_FUNC_R ) 604b5bbe2e3Schristosdnl func_r(...); 605b5bbe2e3Schristosdnl #else 606b5bbe2e3Schristosdnl # if defined( HAVE_THREADS ) 607b5bbe2e3Schristosdnl /* lock */ 608b5bbe2e3Schristosdnl # endif 609b5bbe2e3Schristosdnl func(...); 610b5bbe2e3Schristosdnl # if defined( HAVE_THREADS ) 611b5bbe2e3Schristosdnl /* unlock */ 612b5bbe2e3Schristosdnl # endif 613b5bbe2e3Schristosdnl #endif 614b5bbe2e3Schristosdnl 615b5bbe2e3Schristosdnl HAVE_REENTRANT_FUNCTIONS is derived from: 616b5bbe2e3Schristosdnl _POSIX_REENTRANT_FUNCTIONS 617b5bbe2e3Schristosdnl _POSIX_THREAD_SAFE_FUNCTIONS 618b5bbe2e3Schristosdnl _POSIX_THREADSAFE_FUNCTIONS 619b5bbe2e3Schristosdnl 620b5bbe2e3Schristosdnl and is currently defined in <ldap_pvt_thread.h> 621b5bbe2e3Schristosdnl 622b5bbe2e3Schristosdnl HAVE_THREADS is defined by <ldap_pvt_thread.h> iff -UNO_THREADS 623b5bbe2e3Schristosdnl 624b5bbe2e3Schristosdnl libldap/*.c should only include <ldap_pvt_thread.h> iff 625b5bbe2e3Schristosdnl LDAP_R_COMPILE is defined. ie: 626b5bbe2e3Schristosdnl #ifdef LDAP_R_COMPILE 627b5bbe2e3Schristosdnl # include <ldap_pvt_thread.h> 628b5bbe2e3Schristosdnl #endif 629b5bbe2e3Schristosdnl 630b5bbe2e3Schristosdnl LDAP_R_COMPILE is defined by libldap_r/Makefile.in 631b5bbe2e3Schristosdnl specifically for compiling the threadsafe version of 632b5bbe2e3Schristosdnl the ldap library (-lldap_r). 633b5bbe2e3Schristosdnl 634b5bbe2e3Schristosdnl dnl check for reentrant/threadsafe functions 635b5bbe2e3Schristosdnl dnl 636b5bbe2e3Schristosdnl dnl note: these should only be used when linking 637b5bbe2e3Schristosdnl dnl with $LTHREAD_LIBS 638b5bbe2e3Schristosdnl dnl 639b5bbe2e3Schristosdnl save_CPPFLAGS="$CPPFLAGS" 640b5bbe2e3Schristosdnl save_LIBS="$LIBS" 641b5bbe2e3Schristosdnl LIBS="$LTHREAD_LIBS $LIBS" 642b5bbe2e3Schristosdnl AC_CHECK_FUNCS( \ 643b5bbe2e3Schristosdnl gmtime_r \ 644b5bbe2e3Schristosdnl gethostbyaddr_r gethostbyname_r \ 645b5bbe2e3Schristosdnl feof_unlocked unlocked_feof \ 646b5bbe2e3Schristosdnl putc_unlocked unlocked_putc \ 647b5bbe2e3Schristosdnl flockfile ftrylockfile \ 648b5bbe2e3Schristosdnl ) 649b5bbe2e3Schristosdnl CPPFLAGS="$save_CPPFLAGS" 650b5bbe2e3Schristosdnl LIBS="$save_LIBS" 651b5bbe2e3Schristosfi 652b5bbe2e3Schristos 653b5bbe2e3Schristosif test $ol_link_threads = no ; then 654b5bbe2e3Schristos if test $ol_with_threads = yes ; then 655b5bbe2e3Schristos AC_MSG_ERROR([no suitable thread support]) 656b5bbe2e3Schristos fi 657b5bbe2e3Schristos 658b5bbe2e3Schristos if test $ol_with_threads = auto ; then 659b5bbe2e3Schristos AC_MSG_WARN([no suitable thread support, disabling threads]) 660b5bbe2e3Schristos ol_with_threads=no 661b5bbe2e3Schristos fi 662b5bbe2e3Schristos 663b5bbe2e3Schristos AC_DEFINE([NO_THREADS], [1], 664b5bbe2e3Schristos [define if you have (or want) no threads]) 665b5bbe2e3Schristos LTHREAD_LIBS="" 666b5bbe2e3Schristos BUILD_THREAD=no 667b5bbe2e3Schristoselse 668b5bbe2e3Schristos BUILD_THREAD=yes 669b5bbe2e3Schristosfi 670b5bbe2e3Schristos 671b5bbe2e3Schristosif test $ol_link_threads != no ; then 672b5bbe2e3Schristos AC_DEFINE([LDAP_API_FEATURE_X_OPENLDAP_THREAD_SAFE], [1], 673b5bbe2e3Schristos [define to 1 if library is thread safe]) 674b5bbe2e3Schristosfi 675b5bbe2e3Schristos 676b5bbe2e3Schristos# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: 677b5bbe2e3Schristoscase "$ol_with_threads" in 678b5bbe2e3Schristos no) 679b5bbe2e3Schristos ol_pthread_ok=no 680b5bbe2e3Schristos $2 681b5bbe2e3Schristos ;; 682b5bbe2e3Schristos *) 683b5bbe2e3Schristos ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1]) 684b5bbe2e3Schristos ;; 685b5bbe2e3Schristosesac 686b5bbe2e3Schristos 687b5bbe2e3SchristosAC_LANG_RESTORE 688*a6f3f22fSchristos 689*a6f3f22fSchristosAC_SUBST(BUILD_THREAD) 690*a6f3f22fSchristosAC_SUBST(LTHREAD_LIBS) 691*a6f3f22fSchristos 692b5bbe2e3Schristos]) 693