summaryrefslogtreecommitdiffstats
path: root/gl/glthread/threadlib.c
diff options
context:
space:
mode:
authorHolger Weiss <holger@zedat.fu-berlin.de>2013-08-19 23:27:12 +0200
committerHolger Weiss <holger@zedat.fu-berlin.de>2013-08-19 23:27:12 +0200
commit26fbe7f1e68bb0c96da32491efcf3696fe6c299b (patch)
treec4d95289187a64e9c7517bf73d8208026c3d2fb3 /gl/glthread/threadlib.c
parent5f79e3e9f62ca5487d9881973149136ba1d19d3e (diff)
downloadmonitoring-plugins-26fbe7f1e68bb0c96da32491efcf3696fe6c299b.tar.gz
Sync with the latest Gnulib code (6f2d632)
Diffstat (limited to 'gl/glthread/threadlib.c')
-rw-r--r--gl/glthread/threadlib.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/gl/glthread/threadlib.c b/gl/glthread/threadlib.c
new file mode 100644
index 00000000..b4476573
--- /dev/null
+++ b/gl/glthread/threadlib.c
@@ -0,0 +1,73 @@
1/* Multithreading primitives.
2 Copyright (C) 2005-2013 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 General Public License as published by
6 the Free Software Foundation; either version 3, 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
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, see <http://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
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/* The function to be executed by a dummy thread. */
33static void *
34dummy_thread_func (void *arg)
35{
36 return arg;
37}
38
39int
40glthread_in_use (void)
41{
42 static int tested;
43 static int result; /* 1: linked with -lpthread, 0: only with libc */
44
45 if (!tested)
46 {
47 pthread_t thread;
48
49 if (pthread_create (&thread, NULL, dummy_thread_func, NULL) != 0)
50 /* Thread creation failed. */
51 result = 0;
52 else
53 {
54 /* Thread creation works. */
55 void *retval;
56 if (pthread_join (thread, &retval) != 0)
57 abort ();
58 result = 1;
59 }
60 tested = 1;
61 }
62 return result;
63}
64
65# endif
66
67#endif
68
69/* ========================================================================= */
70
71/* This declaration is solely to ensure that after preprocessing
72 this file is never empty. */
73typedef int dummy;