Blame gettext-runtime/gnulib-lib/glthread/threadlib.c

Packit 5b56b6
/* Multithreading primitives.
Packit 5b56b6
   Copyright (C) 2005-2015 Free Software Foundation, Inc.
Packit 5b56b6
Packit 5b56b6
   This program is free software; you can redistribute it and/or modify
Packit 5b56b6
   it under the terms of the GNU General Public License as published by
Packit 5b56b6
   the Free Software Foundation; either version 3, or (at your option)
Packit 5b56b6
   any later version.
Packit 5b56b6
Packit 5b56b6
   This program is distributed in the hope that it will be useful,
Packit 5b56b6
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 5b56b6
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 5b56b6
   GNU General Public License for more details.
Packit 5b56b6
Packit 5b56b6
   You should have received a copy of the GNU General Public License
Packit 5b56b6
   along with this program; if not, see <http://www.gnu.org/licenses/>.  */
Packit 5b56b6
Packit 5b56b6
/* Written by Bruno Haible <bruno@clisp.org>, 2005.  */
Packit 5b56b6
Packit 5b56b6
#include <config.h>
Packit 5b56b6
Packit 5b56b6
/* ========================================================================= */
Packit 5b56b6
Packit 5b56b6
#if USE_POSIX_THREADS
Packit 5b56b6
Packit 5b56b6
/* Use the POSIX threads library.  */
Packit 5b56b6
Packit 5b56b6
# include <pthread.h>
Packit 5b56b6
# include <stdlib.h>
Packit 5b56b6
Packit 5b56b6
# if PTHREAD_IN_USE_DETECTION_HARD
Packit 5b56b6
Packit 5b56b6
/* The function to be executed by a dummy thread.  */
Packit 5b56b6
static void *
Packit 5b56b6
dummy_thread_func (void *arg)
Packit 5b56b6
{
Packit 5b56b6
  return arg;
Packit 5b56b6
}
Packit 5b56b6
Packit 5b56b6
int
Packit 5b56b6
glthread_in_use (void)
Packit 5b56b6
{
Packit 5b56b6
  static int tested;
Packit 5b56b6
  static int result; /* 1: linked with -lpthread, 0: only with libc */
Packit 5b56b6
Packit 5b56b6
  if (!tested)
Packit 5b56b6
    {
Packit 5b56b6
      pthread_t thread;
Packit 5b56b6
Packit 5b56b6
      if (pthread_create (&thread, NULL, dummy_thread_func, NULL) != 0)
Packit 5b56b6
        /* Thread creation failed.  */
Packit 5b56b6
        result = 0;
Packit 5b56b6
      else
Packit 5b56b6
        {
Packit 5b56b6
          /* Thread creation works.  */
Packit 5b56b6
          void *retval;
Packit 5b56b6
          if (pthread_join (thread, &retval) != 0)
Packit 5b56b6
            abort ();
Packit 5b56b6
          result = 1;
Packit 5b56b6
        }
Packit 5b56b6
      tested = 1;
Packit 5b56b6
    }
Packit 5b56b6
  return result;
Packit 5b56b6
}
Packit 5b56b6
Packit 5b56b6
# endif
Packit 5b56b6
Packit 5b56b6
#endif
Packit 5b56b6
Packit 5b56b6
/* ========================================================================= */
Packit 5b56b6
Packit 5b56b6
/* This declaration is solely to ensure that after preprocessing
Packit 5b56b6
   this file is never empty.  */
Packit 5b56b6
typedef int dummy;