Move some code from gnulib module 'lock' to gnulib module 'threadlib'.

This commit is contained in:
Bruno Haible 2008-08-17 14:36:30 +00:00
parent beb6afd544
commit fe3e8299f1
4 changed files with 80 additions and 39 deletions

View File

@ -1,3 +1,11 @@
2008-08-17 Bruno Haible <bruno@clisp.org>
* threadlib.c: New file, extracted from lock.c.
* lock.c (dummy_thread_func, glthread_in_use): Remove functions.
* Makefile.in (SOURCES): Add threadlib.c.
(OBJECTS): Add threadlib.$lo.
(threadlib.lo): New rule.
2008-08-14 Bruno Haible <bruno@clisp.org>
* lock.h (glthread_lock_lock, glthread_lock_unlock,

View File

@ -127,6 +127,7 @@ SOURCES = \
plural.y \
plural-exp.c \
localcharset.c \
threadlib.c \
lock.c \
relocatable.c \
langprefs.c \
@ -157,6 +158,7 @@ OBJECTS = \
plural.$lo \
plural-exp.$lo \
localcharset.$lo \
threadlib.$lo \
lock.$lo \
relocatable.$lo \
langprefs.$lo \
@ -254,6 +256,8 @@ plural-exp.lo: $(srcdir)/plural-exp.c
$(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/plural-exp.c
localcharset.lo: $(srcdir)/localcharset.c
$(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/localcharset.c
threadlib.lo: $(srcdir)/threadlib.c
$(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/threadlib.c
lock.lo: $(srcdir)/lock.c
$(LIBTOOL) --mode=compile $(COMPILE) $(srcdir)/lock.c
relocatable.lo: $(srcdir)/relocatable.c

View File

@ -28,45 +28,6 @@
#if USE_POSIX_THREADS
/* Use the POSIX threads library. */
# if PTHREAD_IN_USE_DETECTION_HARD
/* The function to be executed by a dummy thread. */
static void *
dummy_thread_func (void *arg)
{
return arg;
}
int
glthread_in_use (void)
{
static int tested;
static int result; /* 1: linked with -lpthread, 0: only with libc */
if (!tested)
{
pthread_t thread;
if (pthread_create (&thread, NULL, dummy_thread_func, NULL) != 0)
/* Thread creation failed. */
result = 0;
else
{
/* Thread creation works. */
void *retval;
if (pthread_join (thread, &retval) != 0)
abort ();
result = 1;
}
tested = 1;
}
return result;
}
# endif
/* -------------------------- gl_lock_t datatype -------------------------- */
/* ------------------------- gl_rwlock_t datatype ------------------------- */

View File

@ -0,0 +1,68 @@
/* Multithreading primitives.
Copyright (C) 2005-2008 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published
by the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
USA. */
/* Written by Bruno Haible <bruno@clisp.org>, 2005. */
#include <config.h>
/* ========================================================================= */
#if USE_POSIX_THREADS
/* Use the POSIX threads library. */
# if PTHREAD_IN_USE_DETECTION_HARD
/* The function to be executed by a dummy thread. */
static void *
dummy_thread_func (void *arg)
{
return arg;
}
int
glthread_in_use (void)
{
static int tested;
static int result; /* 1: linked with -lpthread, 0: only with libc */
if (!tested)
{
pthread_t thread;
if (pthread_create (&thread, NULL, dummy_thread_func, NULL) != 0)
/* Thread creation failed. */
result = 0;
else
{
/* Thread creation works. */
void *retval;
if (pthread_join (thread, &retval) != 0)
abort ();
result = 1;
}
tested = 1;
}
return result;
}
# endif
#endif
/* ========================================================================= */