+dnl ----------------------------------------------------------------
+dnl thread support
+dnl ----------------------------------------------------------------
+
+dnl defines UNIX_THREAD it contains the source file to use for threads. (GL)
+dnl defines THREADS_LINK it contains the thread library to link with. (GL)
+dnl defines wxUSE_THREADS if thread support is activated. (GL)
+
+THREADS_LINK=""
+UNIX_THREAD=""
+
+if test "$wxUSE_THREADS" = "1"; then
+ dnl find if POSIX threads are available
+
+ dnl standard lib name is pthread
+ dnl We no longer test for pthread-0.7 as it breaks compilation on some
+ dnl glibc2 systems, especially for static linkage.
+ AC_CHECK_LIB(pthread, pthread_create, [
+ UNIX_THREAD="unix/threadpsx.cpp"
+ THREADS_LINK="pthread"
+ ], [
+ dnl thread functions are in libc_r under FreeBSD
+ AC_CHECK_LIB(c_r, pthread_create, [
+ UNIX_THREAD="unix/threadpsx.cpp"
+ THREADS_LINK="c_r"
+ ], [
+ dnl VZ: SGI threads are not supported currently
+ AC_CHECK_HEADER(sys/prctl.h, [
+ UNIX_THREAD="gtk/threadsgi.cpp"
+ ])
+ ])
+ ])
+ if test "$THREADS_LINK" != ""; then
+ AC_DEFINE(wxUSE_THREADS)
+ else
+ AC_MSG_WARN(No thread support on this system)
+ fi
+fi
+
+if test -z "$UNIX_THREAD"; then
+ wxUSE_THREADS=0
+fi
+
+dnl do other tests only if we are using threads
+if test "$wxUSE_THREADS" = "1"; then
+
+ dnl define autoconf macro to check for given function in both pthread and
+ dnl posix4 libraries
+ dnl usage: AC_FUNC_THREAD(FUNCTION_NAME)
+ dnl VZ: TODO
+ dnl AC_DEFUN(AC_FUNC_THREAD,
+ dnl [
+ dnl AC_CHECK_LIB($THREADS_LINK, $1,
+ dnl AC_DEFINE(HAVE_`'translit($1, `A-Z', 'a-z'),
+ dnl [AC_CHECK_LIB("posix4", $1,
+ dnl [AC_DEFINE(HAVE_`'translit($1, `A-Z', 'a-z'))
+ dnl POSIX4_LINK="-lposix4"
+ dnl ])
+ dnl ])
+ dnl ])
+
+ AC_CHECK_HEADERS(sched.h)
+
+ AC_CHECK_LIB($THREADS_LINK, sched_yield,
+ AC_DEFINE(HAVE_SCHED_YIELD),
+ [AC_CHECK_LIB("posix4", sched_yield,
+ [AC_DEFINE(HAVE_SCHED_YIELD) POSIX4_LINK="-lposix4"],
+ AC_MSG_WARN(wxThread::Yield() will not work properly)
+ )]
+ )
+
+ dnl VZ: we should be checking for all of the following functions instead:
+ dnl 1. pthread_attr_getschedpolicy
+ dnl 2. sched_get_priority_min and sched_get_priority_max
+ dnl 3. pthread_attr_getschedparam and pthread_attr_setschedparam
+ dnl but it seems that if the first one is there, the other ones are too (of
+ dnl course the proper solution would be to implement AC_FUNC_THREAD above
+ dnl and do test for them all - anyone?)
+ AC_CHECK_LIB($THREADS_LINK, pthread_attr_getschedpolicy,
+ AC_DEFINE(HAVE_THREAD_PRIORITY_FUNCTIONS),
+ [AC_CHECK_LIB("posix4", pthread_attr_getschedpolicy,
+ [AC_DEFINE(HAVE_THREAD_PRIORITY_FUNCTIONS) POSIX4_LINK="-lposix4"],
+ AC_MSG_WARN(Setting thread priority will not work)
+ )]
+ )
+
+ AC_CHECK_LIB($THREADS_LINK, pthread_cancel,
+ AC_DEFINE(HAVE_PTHREAD_CANCEL),
+ AC_MSG_WARN(wxThread::Kill() will not work properly))
+
+ AC_MSG_CHECKING([for pthread_cleanup_push/pop])
+ AC_TRY_COMPILE([#include <pthread.h>],
+ [
+ pthread_cleanup_push(NULL, NULL);
+ pthread_cleanup_pop(0);
+ ],
+ [AC_MSG_RESULT(yes)
+ AC_DEFINE(HAVE_THREAD_CLEANUP_FUNCTIONS)
+ ],
+ [AC_MSG_RESULT(no)]
+ )
+
+ THREADS_LINK="-l$THREADS_LINK"
+fi
+
+AC_SUBST(UNIX_THREAD)
+AC_SUBST(THREADS_LINK)
+AC_SUBST(POSIX4_LINK)
+