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
5    it under the terms of the GNU Lesser General Public License as published by
6    the Free Software Foundation; either version 2.1 of the License, or
7    (at your option) 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
12    GNU Lesser General Public License for more details.
13 
14    You should have received a copy of the GNU Lesser General Public License
15    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
16 
17 /* Written by Bruno Haible <bruno@clisp.org>, 2005.  */
18 
19 #include <config.h>
20 
21 /* ========================================================================= */
22 
23 #if USE_POSIX_THREADS || USE_ISOC_AND_POSIX_THREADS
24 
25 /* Use the POSIX threads library.  */
26 
27 # include <pthread.h>
28 # include <stdlib.h>
29 
30 # if PTHREAD_IN_USE_DETECTION_HARD
31 
32 static pthread_once_t dummy_once_control = PTHREAD_ONCE_INIT;
33 static void
dummy_once_func(void)34 dummy_once_func (void)
35 {
36 }
37 
38 int
glthread_in_use(void)39 glthread_in_use (void)
40 {
41   static int tested;
42   static int result; /* 1: linked with -lpthread, 0: only with libc */
43 
44   if (!tested)
45     {
46       if (pthread_once (&dummy_once_control, dummy_once_func) != 0)
47         result = 0;
48       else
49         result = 1;
50       tested = 1;
51     }
52   return result;
53 }
54 
55 # endif
56 
57 #endif
58 
59 /* ========================================================================= */
60 
61 /* This declaration is solely to ensure that after preprocessing
62    this file is never empty.  */
63 typedef int dummy;
64