+
+ol_link_threads=no
+if test $ol_with_threads = auto -o $ol_with_threads = posix ; then
+ AC_CHECK_HEADERS(pthread.h sched.h)
+
+ if test $ac_cv_header_pthread_h = yes ; then
+ OL_POSIX_THREAD_VERSION
+
+ if test $ol_cv_pthread_version = final ; then
+ dnl AC_DEFINE(HAVE_PTHREADS_FINAL)
+ elif test $ol_cv_pthread_version = draft4 ; then
+ AC_DEFINE(HAVE_PTHREADS_D4)
+ else
+ AC_MSG_ERROR([unknown pthread version])
+ fi
+
+ # consider threads found
+ ol_with_threads=found
+
+ OL_LINUX_THREADS
+
+ if test $ol_cv_linux_threads = yes ; then
+ AC_DEFINE(HAVE_LINUX_THREADS,1)
+ fi
+
+ dnl Now the hard part, how to link
+
+ dnl A few platforms have pthread support in standard libraries
+ AC_CHECK_FUNC(pthread_create,[ol_link_threads=yes])
+
+ 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 CPPFLAGS
+ save_LIBS="$LIBS"
+ LIBS="-pthread $LIBS"
+ AC_TRY_LINK([#include <pthread.h>],[
+ pthread_create((pthread_t*) 0,
+ (pthread_attr_t*) 0, 0, 0);
+ ], 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 -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 DEC Threads
+ save_LIBS="$LIBS"
+ AC_CHECK_LIB(pthread, pthread_create, [
+ AC_DEFINE(HAVE_DCE)
+ ol_link_threads=posix
+ LTHREAD_LIBS="$LTHREAD_LIBS -lpthread -lmach -lexc -lc"],,
+ if test $with_preemptive = auto ; then
+ ol_with_preemptive=yes
+ fi
+ [-lmach -lexc -lc])
+ LIBS="$save_LIBS"
+ fi
+
+ if test $ol_link_threads != no ; then
+ AC_DEFINE(HAVE_PTHREADS)
+
+ dnl save DEFS/LIBS
+ save_CPPFLAGS="$CPPFLAGS"
+ save_LIBS="$LIBS"
+ LIBS="$LTHREAD_LIBS $LIBS"
+
+ dnl All POSIX Thread (final) implementations should have
+ dnl sched_yield instead of pthread yield.
+ dnl check for both
+ AC_CHECK_FUNCS(sched_yield pthread_yield)
+
+ if test $ac_cv_func_sched_yield = no -a \
+ $ac_cv_func_pthread_yield = no ; then
+
+ AC_MSG_WARN([could not locate sched_yield() or pthread_yield()])
+ AC_MSG_ERROR([POSIX Threads are not usable])
+ fi
+
+ dnl Check functions for compatibility
+ AC_CHECK_FUNCS(pthread_kill)
+dnl AC_CHECK_FUNCS(
+dnl pthread_attr_create pthread_attr_init \
+dnl pthread_attr_destroy pthread_attr_delete \
+dnl pthread_attr_setdetachstate pthread_attr_setdetach_np \
+dnl )
+
+ dnl Check PREEMPTIVE Implementation
+ if test $ol_with_preemptive = auto ; then
+ AC_MSG_CHECKING([for preemptive Pthread implementation])
+ AC_TRY_RUN([
+#include <sys/types.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <pthread.h>
+#ifndef NULL
+#define NULL 0
+#endif
+
+int task(arg)
+ int *arg;
+{
+ struct timeval tv;
+
+ tv.tv_sec=4;
+ tv.tv_usec=0;
+ select(0, NULL, NULL, NULL, &tv);
+
+ tv.tv_sec=6;
+ tv.tv_usec=0;
+ select(0, NULL, NULL, NULL, &tv);
+
+ exit(1); /* if we exit here, the select blocked the whole process */
+}
+
+main(argc, argv)
+int argc; char **argv;
+{
+ pthread_t t;
+ pthread_create(&t, NULL, (void *) task, NULL);
+
+#if HAVE_SCHED_YIELD
+ sched_yield(); /* make sure task runs first */
+#else
+#if defined(HAVE_PTHREAD_YIELD)
+ pthread_yield(); /* make sure task runs first */
+#endif
+#endif
+ exit(0);
+}
+ ], [ol_pthread_preemptive=yes], [ol_pthread_preemptive=no], [
+ AC_MSG_ERROR([crossing compiling: use --with-preemptive=yes|no|manual])])
+ AC_MSG_RESULT($ol_pthread_preemptive)
+
+ if test $ol_pthread_preemptive = yes ; then
+ AC_DEFINE(HAVE_PREEMPTIVE_PTHREADS)
+ ol_with_preemptive=yes
+ fi
+ fi
+
+ dnl restore DEFS/LIBS
+ CPPFLAGS="$save_CPPFLAGS"
+ LIBS="$save_LIBS"
+ else
+ AC_MSG_ERROR([could not link with POSIX Threads])
+ fi
+ fi
+
+ if test $ol_with_threads = posix ; then
+ AC_MSG_ERROR([could not locate POSIX Threads])
+ fi