maint: update copyright
[gnulib.git] / m4 / pthread.m4
1 # pthread.m4 serial 7
2 dnl Copyright (C) 2009-2014 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    gl_CHECK_NEXT_HEADERS([pthread.h])
11    if test $ac_cv_header_pthread_h = yes; then
12      HAVE_PTHREAD_H=1
13    else
14      HAVE_PTHREAD_H=0
15    fi
16
17    AC_CHECK_TYPES([pthread_t, pthread_spinlock_t], [], [],
18      [AC_INCLUDES_DEFAULT[
19       #if HAVE_PTHREAD_H
20        #include <pthread.h>
21       #endif]])
22    if test $ac_cv_type_pthread_t != yes; then
23      HAVE_PTHREAD_T=0
24    fi
25    if test $ac_cv_type_pthread_spinlock_t != yes; then
26      HAVE_PTHREAD_SPINLOCK_T=0
27    fi
28
29    if test $ac_cv_header_pthread_h != yes ||
30       test $ac_cv_type_pthread_t != yes ||
31       test $ac_cv_type_pthread_spinlock_t != yes; then
32      PTHREAD_H='pthread.h'
33      AC_LIBOBJ([pthread])
34    else
35      PTHREAD_H=
36    fi
37    AC_SUBST([PTHREAD_H])
38    AM_CONDITIONAL([GL_GENERATE_PTHREAD_H], [test -n "$PTHREAD_H"])
39
40    LIB_PTHREAD=
41    if test $ac_cv_header_pthread_h = yes; then
42      dnl We cannot use AC_SEARCH_LIBS here, because on OSF/1 5.1 pthread_join
43      dnl is defined as a macro which expands to __phread_join, and libpthread
44      dnl contains a definition for __phread_join but none for pthread_join.
45      dnl Also, FreeBSD 9 puts pthread_create in libpthread and pthread_join
46      dnl in libc, whereas on IRIX 6.5 the reverse is true; so check for both.
47      AC_CACHE_CHECK([for library containing pthread_create and pthread_join],
48        [gl_cv_lib_pthread],
49        [gl_saved_libs=$LIBS
50         gl_cv_lib_pthread=
51         for gl_lib_prefix in '' '-lpthread'; do
52           LIBS="$gl_lib_prefix $gl_saved_libs"
53           AC_LINK_IFELSE(
54             [AC_LANG_PROGRAM(
55                [[#include <pthread.h>
56                  void *noop (void *p) { return p; }]],
57                [[pthread_t pt;
58                  void *arg = 0;
59                  pthread_create (&pt, 0, noop, arg);
60                  pthread_join (pthread_self (), &arg);]])],
61             [if test -z "$gl_lib_prefix"; then
62                gl_cv_lib_pthread="none required"
63              else
64                gl_cv_lib_pthread=$gl_lib_prefix
65              fi])
66           test -n "$gl_cv_lib_pthread" && break
67         done
68         LIBS="$gl_saved_libs"
69        ])
70      if test "$gl_cv_lib_pthread" != "none required"; then
71        LIB_PTHREAD="$gl_cv_lib_pthread"
72      fi
73    fi
74    AC_SUBST([LIB_PTHREAD])
75
76    AC_REQUIRE([AC_C_RESTRICT])
77 ])
78
79 AC_DEFUN([gl_PTHREAD_DEFAULTS],
80 [
81   dnl Assume proper GNU behavior unless another module says otherwise.
82   HAVE_PTHREAD_H=1;              AC_SUBST([HAVE_PTHREAD_H])
83   HAVE_PTHREAD_T=1;              AC_SUBST([HAVE_PTHREAD_T])
84   HAVE_PTHREAD_SPINLOCK_T=1;     AC_SUBST([HAVE_PTHREAD_SPINLOCK_T])
85 ])