From: Bruno Haible Date: Sun, 17 Aug 2008 14:26:05 +0000 (+0200) Subject: Move some code from module 'lock' to module 'threadlib'. X-Git-Tag: v0.1~7148 X-Git-Url: http://erislabs.net/gitweb/?a=commitdiff_plain;h=429bd1c00170c0e6d449e6269b71803b10ce6af0;p=gnulib.git Move some code from module 'lock' to module 'threadlib'. --- diff --git a/ChangeLog b/ChangeLog index 062b03ec0..e50ea6f39 100644 --- a/ChangeLog +++ b/ChangeLog @@ -18,6 +18,10 @@ New module 'threadlib'. * modules/threadlib: New file. + * lib/glthread/threadlib.c: New file, extracted from + lib/glthread/lock.c. + * lib/glthread/lock.c (dummy_thread_func, glthread_in_use): Remove + functions. * m4/threadlib.m4: New file, from m4/lock.m4, renaming gl_LOCK to gl_THREADLIB and gl_LOCK_EARLY to gl_THREADLIB_EARLY. * m4/lock.m4 (gl_LOCK_EARLY, gl_LOCK_EARLY_BODY, gl_LOCK_BODY): Remove diff --git a/lib/glthread/lock.c b/lib/glthread/lock.c index 1391617c8..2ad0e06e7 100644 --- a/lib/glthread/lock.c +++ b/lib/glthread/lock.c @@ -27,45 +27,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 ------------------------- */ diff --git a/lib/glthread/threadlib.c b/lib/glthread/threadlib.c new file mode 100644 index 000000000..a1601deb6 --- /dev/null +++ b/lib/glthread/threadlib.c @@ -0,0 +1,67 @@ +/* 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 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 General Public License for more details. + + You should have received a copy of the GNU 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 , 2005. */ + +#include + +/* ========================================================================= */ + +#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 + +/* ========================================================================= */ diff --git a/modules/threadlib b/modules/threadlib index ac659ea8f..9e3438c78 100644 --- a/modules/threadlib +++ b/modules/threadlib @@ -2,6 +2,7 @@ Description: Access to multithreading primitives. Files: +lib/glthread/threadlib.c m4/threadlib.m4 build-aux/config.rpath @@ -15,6 +16,7 @@ configure.ac: gl_THREADLIB Makefile.am: +lib_SOURCES += glthread/threadlib.c Include: