390
391
dnl ----------------------------------------------------------------------
395
dnl Find a thread library to use. Sets ETHR_LIBS to libraries to link
396
dnl with, ETHR_X_LIBS to extra libraries to link with (same as ETHR_LIBS
397
dnl except that the ethread lib itself is not included), ETHR_DEFS to
398
dnl defines to compile with, ETHR_THR_LIB_BASE to the name of the
399
dnl thread library which the ethread library is based on, and ETHR_LIB_NAME
400
dnl to the name of the library where the ethread implementation is located.
401
dnl LM_FIND_ETHR_LIB currently searches for 'pthreads', and
402
dnl 'win32_threads'. If no thread library was found ETHR_LIBS, ETHR_X_LIBS,
403
dnl ETHR_DEFS, ETHR_THR_LIB_BASE, and ETHR_LIB_NAME are all set to the
407
AC_DEFUN(LM_FIND_ETHR_LIB,
410
dnl Name of lib where ethread implementation is located
411
ethr_lib_name=ethread
414
ETHR_THR_LIB_BASE_NAME=
420
dnl if test "x$host_os" = "x"; then
421
dnl AC_CANONICAL_HOST
425
AC_MSG_CHECKING([for native win32 threads])
426
if test "X$host_os" = "Xwin32"; then
430
ETHR_THR_LIB_BASE=win32_threads
431
AC_DEFINE(ETHR_WIN32_THREADS, 1, [Define if you have win32 threads])
433
AC_CACHE_CHECK([for InitializeCriticalSectionAndSpinCount],
434
ethr_cv_func_initializecriticalsectionandspincount,
435
AC_TRY_LINK([#include <windows.h>],
436
[CRITICAL_SECTION cs;
437
InitializeCriticalSectionAndSpinCount(&cs, 1000);],
438
ethr_cv_func_initializecriticalsectionandspincount=yes,
439
ethr_cv_func_initializecriticalsectionandspincount=no))
440
if test $ethr_cv_func_initializecriticalsectionandspincount = yes; then
441
AC_DEFINE(ETHR_HAVE_INITIALIZECRITICALSECTIONANDSPINCOUNT, 1, \
442
[Define if you have the InitializeCriticalSectionAndSpinCount function])
445
AC_CACHE_CHECK([for TryEnterCriticalSection],
446
ethr_cv_func_tryentercriticalsection,
447
AC_TRY_LINK([#include <windows.h>],
448
[CRITICAL_SECTION cs;
449
TryEnterCriticalSection(&cs);],
450
ethr_cv_func_tryentercriticalsection=yes,
451
ethr_cv_func_tryentercriticalsection=no))
452
if test $ethr_cv_func_tryentercriticalsection = yes; then
453
AC_DEFINE(ETHR_HAVE_TRYENTERCRITICALSECTION, 1, \
454
[Define if you have the TryEnterCriticalSection function])
459
dnl Try to find POSIX threads
461
dnl The usual pthread lib...
462
AC_CHECK_LIB(pthread, pthread_create, ETHR_X_LIBS="-lpthread")
464
dnl FreeBSD has pthreads in special c library, c_r...
465
if test "x$ETHR_X_LIBS" = "x"; then
466
AC_CHECK_LIB(c_r, pthread_create, ETHR_X_LIBS="-lc_r")
469
dnl On ofs1 the '-pthread' switch should be used
470
if test "x$ETHR_X_LIBS" = "x"; then
471
AC_MSG_CHECKING([if the '-pthread' switch can be used])
473
CFLAGS="$CFLAGS -pthread"
474
AC_TRY_LINK([#include <pthread.h>],
475
pthread_create((void*)0,(void*)0,(void*)0,(void*)0);,
476
[ETHR_DEFS="-pthread"
477
ETHR_X_LIBS="-pthread"])
479
if test "x$ETHR_X_LIBS" != "x"; then
486
if test "x$ETHR_X_LIBS" != "x"; then
487
ETHR_DEFS="$ETHR_DEFS -D_THREAD_SAFE -D_REENTRANT"
488
ETHR_THR_LIB_BASE=pthread
489
AC_DEFINE(ETHR_PTHREADS, 1, [Define if you have pthreads])
492
ETHR_DEFS="$ETHR_DEFS -D_POSIX_PTHREAD_SEMANTICS" ;;
494
ETHR_DEFS="$ETHR_DEFS -D_POSIX_THREAD_SAFE_FUNCTIONS -D_GNU_SOURCE"
495
linux_kernel_vsn_=`uname -r` # FIXME: for cross compilation.
498
usable_sigaltstack=no
500
# FIXME: Test for actual problems instead of kernel versions.
501
case $linux_kernel_vsn_ in
502
[[0-1]].*|2.[[0-1]]|2.[[0-1]].*)
504
2.[[2-3]]|2.[[2-3]].*)
509
usable_sigaltstack=yes
513
AC_MSG_CHECKING(if SIGUSR1 and SIGUSR2 can be used)
514
AC_MSG_RESULT($usable_sigusrx)
515
if test $usable_sigusrx = no; then
516
ETHR_DEFS="$ETHR_DEFS -DETHR_UNUSABLE_SIGUSRX"
519
AC_MSG_CHECKING(if sigaltstack can be used)
520
AC_MSG_RESULT($usable_sigaltstack)
521
if test $usable_sigaltstack = no; then
522
ETHR_DEFS="$ETHR_DEFS -DETHR_UNUSABLE_SIGALTSTACK"
525
AC_MSG_CHECKING(for Native POSIX Thread Library)
526
case `getconf GNU_LIBPTHREAD_VERSION 2>/dev/null` in
532
if test $nptl = yes; then
533
ETHR_THR_LIB_BASE_NAME=nptl
535
if test $nptl = yes; then
537
AC_CHECK_HEADER(nptl/pthread.h, need_nptl_incldir=yes)
538
if test $need_nptl_incldir = yes; then
540
nptl_path="$C_INCLUDE_PATH:$CPATH:/usr/local/include:/usr/include"
542
save_ifs="$IFS"; IFS=":"
543
for dir in $nptl_path; do
544
if test "x$dir" != "x"; then
545
nptl_ws_path="$nptl_ws_path $dir"
550
for dir in $nptl_ws_path; do
551
AC_CHECK_HEADER($dir/nptl/pthread.h,
552
nptl_incldir=$dir/nptl)
553
if test "x$nptl_incldir" != "x"; then
554
ETHR_DEFS="$ETHR_DEFS -isystem $nptl_incldir"
558
if test "x$nptl_incldir" = "x"; then
559
AC_MSG_ERROR(Failed to locate nptl system include directory)
564
AC_DEFINE(ETHR_INIT_MUTEX_IN_CHILD_AT_FORK, 1, \
565
[Define if mutexes should be reinitialized (instead of unlocked) in child at fork.]) ;;
569
dnl We sometimes need ETHR_DEFS in order to find certain headers
570
dnl (at least for pthread.h on osf1).
571
saved_cppflags=$CPPFLAGS
572
CPPFLAGS="$CPPFLAGS $ETHR_DEFS"
574
dnl We need the thread library in order to find some functions
576
LIBS="$LIBS $ETHR_X_LIBS"
581
dnl Check for headers
584
AC_CHECK_HEADER(pthread.h,
585
AC_DEFINE(ETHR_HAVE_PTHREAD_H, 1, \
586
[Define if you have the <pthread.h> header file.]))
588
dnl Some Linuxes have <pthread/mit/pthread.h> instead of <pthread.h>
589
AC_CHECK_HEADER(pthread/mit/pthread.h, \
590
AC_DEFINE(ETHR_HAVE_MIT_PTHREAD_H, 1, \
591
[Define if the pthread.h header file is in pthread/mit directory.]))
593
AC_CHECK_HEADER(sys/time.h, \
594
AC_DEFINE(ETHR_HAVE_SYS_TIME_H, 1, \
595
[Define if you have the <sys/time.h> header file.]))
597
AC_TRY_COMPILE([#include <time.h>
598
#include <sys/time.h>],
599
[struct timeval *tv; return 0;],
600
AC_DEFINE(ETHR_TIME_WITH_SYS_TIME, 1, \
601
[Define if you can safely include both <sys/time.h> and <time.h>.]))
605
dnl Check for functions
608
AC_CHECK_FUNC(pthread_atfork, \
609
AC_DEFINE(ETHR_HAVE_PTHREAD_ATFORK, 1, \
610
[Define if you have the pthread_atfork function.]))
611
AC_CHECK_FUNC(pthread_mutexattr_settype, \
612
AC_DEFINE(ETHR_HAVE_PTHREAD_MUTEXATTR_SETTYPE, 1, \
613
[Define if you have the pthread_mutexattr_settype function.]))
614
AC_CHECK_FUNC(pthread_mutexattr_setkind_np, \
615
AC_DEFINE(ETHR_HAVE_PTHREAD_MUTEXATTR_SETKIND_NP, 1, \
616
[Define if you have the pthread_mutexattr_setkind_np function.]))
623
CPPFLAGS=$saved_cppflags
628
if test "x$ETHR_THR_LIB_BASE" != "x"; then
629
ETHR_DEFS="-DUSE_THREADS $ETHR_DEFS"
630
ETHR_LIBS="-l$ethr_lib_name $ETHR_X_LIBS"
631
ETHR_LIB_NAME=$ethr_lib_name
634
AC_DEFINE(ETHR_HAVE_ETHREAD_DEFINES, 1, \
635
[Define if you have all ethread defines])
637
AC_SUBST(ETHR_X_LIBS)
639
AC_SUBST(ETHR_LIB_NAME)
641
AC_SUBST(ETHR_THR_LIB_BASE)
642
AC_SUBST(ETHR_THR_LIB_BASE_NAME)
648
dnl ----------------------------------------------------------------------
392
650
dnl ERL_TIME_CORRECTION
394
652
dnl In the presence of a high resolution realtime timer Erlang can adapt