- # consider threads found
- ol_with_threads=found
-
- OL_LINUX_THREADS
-
- if test $ol_cv_linux_threads = yes ; then
- AC_DEFINE(HAVE_LINUX_THREADS,1,
- [define if you have LinuxThreads])
- fi
-
- dnl Now the hard part, how to link?
- dnl
- dnl currently supported checks:
- dnl
- dnl Check for no flags
- dnl pthread_create() in $LIBS
- dnl
- dnl Check special pthread (final) flags
- dnl pthread_create() with -mt (Solaris)
- dnl pthread_create() with -kthread (FreeBSD)
- dnl pthread_create() with -pthread (FreeBSD/Digital Unix)
- dnl pthread_create() with -pthreads (?)
- dnl pthread_create() with -thread (?)
- dnl
- dnl Check pthread (final) libraries
- dnl pthread_mutex_unlock() in -lpthread -lmach -lexc -lc_r (OSF/1)
- dnl pthread_mutex_lock() in -lpthread -lmach -lexc (OSF/1)
- dnl pthread_mutex_trylock() in -lpthread -lexc (OSF/1)
- dnl pthread_create() in -lpthread (many)
- dnl pthread_create() in -lc_r (FreeBSD)
- dnl pthread_create() in -lpthreads (many)
- dnl pthread_join() -Wl,-woff,85 -lpthreads (IRIX)
- dnl
- dnl Check pthread (draft4) flags (depreciated)
- dnl pthread_create() with -threads (OSF/1)
- dnl
- dnl Check pthread (final) libraries (depreciated)
- dnl pthread_mutex_unlock() in -lpthreads -lmach -lexc -lc_r (OSF/1)
- dnl pthread_mutex_lock() in -lpthreads -lmach -lexc (OSF/1)
- dnl pthread_mutex_trylock() in -lpthreads -lexc (OSF/1)
- dnl
-
- dnl pthread_create in $LIBS
- AC_MSG_CHECKING([for pthread_create in default libraries])
- AC_CACHE_VAL(ol_cv_pthread_create,[
- AC_TRY_RUN([
-#include <pthread.h>
-#ifndef NULL
-#define NULL (void*)0
-#endif
-
-static void *task(p)
- void *p;
-{
- return (void *) (p == NULL);
-}
-
-int main(argc, argv)
- int argc;
- char **argv;
-{
- pthread_t t;
- int status;
-
- /* make sure pthread_create() isn't just a stub */
-#if HAVE_PTHREADS_D4
- status = pthread_create(&t, pthread_attr_default, task, NULL));
-#else
- status = pthread_create(&t, NULL, task, NULL);
-#endif
-
- if( status ) return status;
-
- /* make sure pthread_detach() isn't just a stub */
-#if HAVE_PTHREADS_D4
- status = pthread_detach( &t );
-#else
- status = pthread_detach( t );
-#endif
-
- if( status ) return status;
-
- return status;
-}
-],
- [ol_cv_pthread_create=yes],
- [ol_cv_pthread_create=no],
- [dnl assume yes
- ol_cv_pthread_create=yes])])
- AC_MSG_RESULT($ol_cv_pthread_create)
-
- if test $ol_cv_pthread_create != no ; then
- ol_link_threads=posix
- fi
-
- if test $ol_link_threads = no ; then
- dnl try -mt
- AC_CACHE_CHECK([for pthread_create with -mt],
- [ol_cv_thread_flag], [
- dnl save the flags
- save_LIBS="$LIBS"
- LIBS="-mt $LIBS"
- AC_TRY_LINK([char pthread_create();],
- [pthread_create();],
- [ol_cv_thread_flag=yes], [ol_cv_thread_flag=no])
- dnl restore the LIBS
- LIBS="$save_LIBS"
- ])
-
- if test $ol_cv_thread_flag = yes ; then
- LTHREAD_LIBS="$LTHREAD_LIBS -mt"
- ol_link_threads=posix
- fi
- fi
-
- if test $ol_link_threads = no ; then
- dnl try -kthread
- AC_CACHE_CHECK([for pthread_create with -kthread],
- [ol_cv_kthread_flag], [
- dnl save the flags
- save_LIBS="$LIBS"
- LIBS="-kthread $LIBS"
- AC_TRY_LINK([#include <pthread.h>],[
-#if HAVE_PTHREADS_D4
- pthread_create(NULL,pthread_attr_default,NULL,NULL);
-#else
- pthread_t t;
- pthread_create(&t,NULL,NULL,NULL);
- pthread_detach(t);
-#endif
-],
- [ol_cv_kthread_flag=yes], [ol_cv_kthread_flag=no])
- dnl restore the LIBS
- LIBS="$save_LIBS"
- ])
-
- if test $ol_cv_kthread_flag = yes ; then
- LTHREAD_LIBS="$LTHREAD_LIBS -kthread"
- ol_link_threads=posix
- fi
- fi
-
- if test $ol_link_threads = no ; then
- dnl try -pthread
- AC_CACHE_CHECK([for pthread_create with -pthread],
- [ol_cv_pthread_flag], [
- dnl save the flags
- save_LIBS="$LIBS"
- LIBS="-pthread $LIBS"
- AC_TRY_LINK([#include <pthread.h>],[
-#if HAVE_PTHREADS_D4
- pthread_create(NULL,pthread_attr_default,NULL,NULL);
-#else
- pthread_create(NULL,NULL,NULL,NULL);
-#endif
-],
- [ol_cv_pthread_flag=yes], [ol_cv_pthread_flag=no])
- dnl restore the LIBS
- LIBS="$save_LIBS"
- ])
-
- if test $ol_cv_pthread_flag = yes ; then
- LTHREAD_LIBS="$LTHREAD_LIBS -pthread"
- ol_link_threads=posix
- fi
- fi
-
- if test $ol_link_threads = no ; then
- dnl try -pthreads
- AC_CACHE_CHECK([for pthread_create with -pthreads],
- [ol_cv_pthreads_flag], [
- dnl save the flags
- save_LIBS="$LIBS"
- LIBS="-pthreads $LIBS"
- AC_TRY_LINK([#include <pthread.h>],[
-#if HAVE_PTHREADS_D4
- pthread_create(NULL,pthread_attr_default,NULL,NULL);
-#else
- pthread_create(NULL,NULL,NULL,NULL);
-#endif
-],
- [ol_cv_pthreads_flag=yes], [ol_cv_pthreads_flag=no])
- dnl restore the LIBS
- LIBS="$save_LIBS"
- ])
-
- if test $ol_cv_pthreads_flag = yes ; then
- LTHREAD_LIBS="$LTHREAD_LIBS -pthreads"
- ol_link_threads=posix
- fi
- fi
-
- if test $ol_link_threads = no ; then
- dnl try -thread
- AC_CACHE_CHECK([for pthread_create with -thread],
- [ol_cv_thread_flag], [
- dnl save the flags
- save_LIBS="$LIBS"
- LIBS="-thread $LIBS"
- AC_TRY_LINK([char pthread_create();],
- [pthread_create();],
- [ol_cv_thread_flag=yes], [ol_cv_thread_flag=no])
- dnl restore the LIBS
- LIBS="$save_LIBS"
- ])
-
- if test $ol_cv_thread_flag = yes ; then
- LTHREAD_LIBS="$LTHREAD_LIBS -thread"
- ol_link_threads=posix
- fi
- fi
-
- if test $ol_link_threads = no ; then
- dnl try DEC Threads -lpthread -lmach -lexc -lc_r
- save_LIBS="$LIBS"
- AC_CHECK_LIB(pthread, pthread_mutex_unlock, [
- ol_link_threads=posix
- LTHREAD_LIBS="$LTHREAD_LIBS -lpthread -lmach -lexc -lc_r"
- if test $ol_with_yielding_select = auto ; then
- ol_with_yielding_select=yes
- fi
- ],:,[-lmach -lexc -lc_r])
- LIBS="$save_LIBS"
- fi
-
- if test $ol_link_threads = no ; then
- dnl try DEC Threads -lpthread -lmach -lexc
- save_LIBS="$LIBS"
- AC_CHECK_LIB(pthread, pthread_mutex_lock, [
- ol_link_threads=posix
- LTHREAD_LIBS="$LTHREAD_LIBS -lpthread -lmach -lexc"
- if test $ol_with_yielding_select = auto ; then
- ol_with_yielding_select=yes
- fi
- ],:,[-lmach -lexc])
- LIBS="$save_LIBS"
- fi
-
- if test $ol_link_threads = no ; then
- dnl try DEC Threads -lpthread -lexc
- save_LIBS="$LIBS"
- AC_CHECK_LIB(pthread, pthread_mutex_trylock, [
- ol_link_threads=posix
- LTHREAD_LIBS="$LTHREAD_LIBS -lpthread -lexc"
- if test $ol_with_yielding_select = auto ; then
- ol_with_yielding_select=yes
- fi
- ],:,[-lexc])
- LIBS="$save_LIBS"
- fi
-
- if test $ol_link_threads = no ; then
- dnl try -lpthread
- save_LIBS="$LIBS"
- AC_CHECK_LIB(pthread, pthread_create, [
- ol_link_threads=posix
- LTHREAD_LIBS="$LTHREAD_LIBS -lpthread"],:)
- LIBS="$save_LIBS"
- fi
-
- if test $ol_link_threads = no ; then
- dnl try -lc_r
- save_LIBS="$LIBS"
- AC_CHECK_LIB(c_r, pthread_create, [
- ol_link_threads=posix
- LTHREAD_LIBS="$LTHREAD_LIBS -lc_r"],:)
- LIBS="$save_LIBS"
- fi
-
- if test $ol_link_threads = no ; then
- dnl try -lpthreads
- save_LIBS="$LIBS"
- AC_CHECK_LIB(pthreads, pthread_create, [
- ol_link_threads=posix
- LTHREAD_LIBS="$LTHREAD_LIBS -lpthreads"],:)
- LIBS="$save_LIBS"
- fi
-
- dnl IRIX Pthread check
- if test $ol_link_threads = no ; then
- dnl try IRIX Pthreads -Wl,-woff,85 -lpthreads
- save_LIBS="$LIBS"
- AC_CHECK_LIB(pthreads, pthread_join, [
- ol_link_threads=posix
- LTHREAD_LIBS="$LTHREAD_LIBS -lpthreads"
- ],:,[-Wl,-woff,85])
- LIBS="$save_LIBS"
- fi
-
- if test $ol_link_threads = no ; then
- dnl try -threads
- AC_CACHE_CHECK([for pthread_create with -threads],
- [ol_cv_thread_flag], [
- dnl save the flags
- save_LIBS="$LIBS"
- LIBS="-threads $LIBS"
- AC_TRY_LINK([char pthread_create();],[
- pthread_create();
- ], ol_cv_thread_flag=yes, ol_cv_thread_flag=no)
- dnl restore the LIBS
- LIBS="$save_LIBS"
- ])
-
- if test $ol_cv_thread_flag = yes ; then
- LTHREAD_LIBS="$LTHREAD_LIBS -threads"
- ol_link_threads=posix
- fi
- fi
-
- if test $ol_link_threads = no ; then
- dnl try DEC Threads -lpthreads -lmach -lexc -lc_r
- save_LIBS="$LIBS"
- AC_CHECK_LIB(pthreads, pthread_mutex_unlock, [
- ol_link_threads=posix
- LTHREAD_LIBS="$LTHREAD_LIBS -lpthreads -lmach -lexc -lc_r"
- if test $ol_with_yielding_select = auto ; then
- ol_with_yielding_select=yes
- fi
- ],:,[-lmach -lexc -lc_r])
- LIBS="$save_LIBS"
- fi