mirror of
https://https.git.savannah.gnu.org/git/gettext.git
synced 2026-01-26 15:39:11 +00:00
Move some code from gnulib module 'lock' to gnulib module 'threadlib'.
This commit is contained in:
parent
beb6afd544
commit
fe3e8299f1
@ -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,
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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 ------------------------- */
|
||||
|
||||
68
gettext-runtime/intl/threadlib.c
Normal file
68
gettext-runtime/intl/threadlib.c
Normal 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
|
||||
|
||||
/* ========================================================================= */
|
||||
Loading…
x
Reference in New Issue
Block a user