]> git.deb.at Git - pkg/abook.git/blob - intl/threadlib.c
autotools update: 1/2: main files
[pkg/abook.git] / intl / threadlib.c
1 /* Multithreading primitives.
2    Copyright (C) 2005-2009 Free Software Foundation, Inc.
3
4    This program is free software; you can redistribute it and/or modify it
5    under the terms of the GNU Library General Public License as published
6    by the Free Software Foundation; either version 2, or (at your option)
7    any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Library General Public License for more details.
13
14    You should have received a copy of the GNU Library General Public
15    License along with this program; if not, write to the Free Software
16    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17    USA.  */
18
19 /* Written by Bruno Haible <bruno@clisp.org>, 2005.  */
20
21 #include <config.h>
22
23 /* ========================================================================= */
24
25 #if USE_POSIX_THREADS
26
27 /* Use the POSIX threads library.  */
28
29 # include <pthread.h>
30 # include <stdlib.h>
31
32 # if PTHREAD_IN_USE_DETECTION_HARD
33
34 /* The function to be executed by a dummy thread.  */
35 static void *
36 dummy_thread_func (void *arg)
37 {
38   return arg;
39 }
40
41 int
42 glthread_in_use (void)
43 {
44   static int tested;
45   static int result; /* 1: linked with -lpthread, 0: only with libc */
46
47   if (!tested)
48     {
49       pthread_t thread;
50
51       if (pthread_create (&thread, NULL, dummy_thread_func, NULL) != 0)
52         /* Thread creation failed.  */
53         result = 0;
54       else
55         {
56           /* Thread creation works.  */
57           void *retval;
58           if (pthread_join (thread, &retval) != 0)
59             abort ();
60           result = 1;
61         }
62       tested = 1;
63     }
64   return result;
65 }
66
67 # endif
68
69 #endif
70
71 /* ========================================================================= */
72
73 /* This declaration is solely to ensure that after preprocessing
74    this file is never empty.  */
75 typedef int dummy;