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