pthread: add to system <pthread.h> instead of replacing it all, for MacOS
[gnulib.git] / m4 / pthread.m4
1 # pthread.m4
2 dnl Copyright (C) 2009, 2010 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gl_PTHREAD_CHECK],
8 [
9    AC_REQUIRE([gl_PTHREAD_DEFAULTS])
10    AC_CHECK_HEADERS_ONCE([pthread.h])
11    gl_CHECK_NEXT_HEADERS([pthread.h])
12    if test $ac_cv_header_pthread_h = yes; then
13      HAVE_PTHREAD_H=1
14    else
15      HAVE_PTHREAD_H=0
16    fi
17
18    AC_CHECK_TYPES([pthread_t, pthread_spinlock_t], [], [],
19      [AC_INCLUDES_DEFAULT[
20       #if HAVE_PTHREAD_H
21        #include <pthread.h>
22       #endif]])
23    if test $ac_cv_type_pthread_t != yes; then
24      HAVE_PTHREAD_T=0
25    fi
26    if test $ac_cv_type_pthread_spinlock_t != yes; then
27      HAVE_PTHREAD_SPINLOCK_T=0
28    fi
29
30    if test $ac_cv_header_pthread_h != yes ||
31       test $ac_cv_type_pthread_t != yes ||
32       test $ac_cv_type_pthread_spinlock_t != yes; then
33      PTHREAD_H='pthread.h'
34    fi
35
36    LIB_PTHREAD=
37    if test $ac_cv_header_pthread_h = yes; then
38      gl_saved_libs=$LIBS
39      AC_SEARCH_LIBS([pthread_create], [pthread],
40        [if test "$ac_cv_search_pthread_create" != "none required"; then
41           LIB_PTHREAD="$ac_cv_search_pthread_create"
42         fi])
43      LIBS="$gl_saved_libs"
44    fi
45    AC_SUBST([LIB_PTHREAD])
46
47    AC_REQUIRE([AC_C_INLINE])
48    AC_REQUIRE([AC_C_RESTRICT])
49 ])
50
51 AC_DEFUN([gl_PTHREAD_DEFAULTS],
52 [
53   dnl Assume proper GNU behavior unless another module says otherwise.
54   HAVE_PTHREAD_H=1;              AC_SUBST([HAVE_PTHREAD_H])
55   HAVE_PTHREAD_T=1;              AC_SUBST([HAVE_PTHREAD_T])
56   HAVE_PTHREAD_SPINLOCK_T=1;     AC_SUBST([HAVE_PTHREAD_SPINLOCK_T])
57   PTHREAD_H='';                  AC_SUBST([PTHREAD_H])
58 ])