Blame lib/glthread/threadlib.c

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