Mercurial > hg > octave-kai > gnulib-hg
changeset 17422:08883714ab3e
regex: adapt to locking regime instead of depending on pthread
Instead of depending on pthread, adapt to whatever thread
modules are in use. Problem reported by Ludovic Courtès in
<http://lists.gnu.org/archive/html/bug-gnulib/2013-05/msg00082.html>
and by Mats Erik Andersson in
<http://lists.gnu.org/archive/html/bug-gnulib/2013-05/msg00100.html>.
* lib/regex_internal.h (lock_define, lock_init, lock_fini):
Support either the 'lock' module, or the 'pthread' module, or
no module.
(lock_lock, lock_unlock): New macros.
* lib/regexec.c (regexec, re_search_stub): Use the new macros.
* modules/lock, modules/pthread (configure.ac): Add module indicator.
* modules/regex (Depends-on): Remove pthread.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Wed, 29 May 2013 10:24:17 -0700 |
parents | ce63398f847f |
children | 6105f1dfb98e |
files | ChangeLog lib/regex_internal.h lib/regexec.c modules/lock modules/pthread modules/regex |
diffstat | 6 files changed, 41 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2013-05-29 Paul Eggert <eggert@cs.ucla.edu> + + regex: adapt to locking regime instead of depending on pthread + Instead of depending on pthread, adapt to whatever thread + modules are in use. Problem reported by Ludovic Courtès in + <http://lists.gnu.org/archive/html/bug-gnulib/2013-05/msg00082.html> + and by Mats Erik Andersson in + <http://lists.gnu.org/archive/html/bug-gnulib/2013-05/msg00100.html>. + * lib/regex_internal.h (lock_define, lock_init, lock_fini): + Support either the 'lock' module, or the 'pthread' module, or + no module. + (lock_lock, lock_unlock): New macros. + * lib/regexec.c (regexec, re_search_stub): Use the new macros. + * modules/lock, modules/pthread (configure.ac): Add module indicator. + * modules/regex (Depends-on): Remove pthread. + 2013-05-22 Eric Blake <eblake@redhat.com> getgroups: document portability issues
--- a/lib/regex_internal.h +++ b/lib/regex_internal.h @@ -33,24 +33,33 @@ #include <stdbool.h> #include <stdint.h> -#if defined _LIBC +#ifdef _LIBC # include <bits/libc-lock.h> -#endif -/* Use __libc_lock_define (, NAME) if the library defines the macro, - and if the compiler is known to support empty macro arguments. */ -#if (defined __libc_lock_define \ - && ((defined __GNUC__ && !defined __STRICT_ANSI__) \ - || (defined __STDC_VERSION__ && 199901L <= __STDC_VERSION__))) # define lock_define(name) __libc_lock_define (, name) # define lock_init(lock) (__libc_lock_init (lock), 0) # define lock_fini(lock) 0 -#else +# define lock_lock(lock) __libc_lock_lock (lock) +# define lock_unlock(lock) __libc_lock_unlock (lock) +#elif defined GNULIB_LOCK +# include "glthread/lock.h" +# define lock_define(name) gl_lock_define (, name) +# define lock_init(lock) glthread_lock_init (&(lock)) +# define lock_fini(lock) glthread_lock_destroy (&(lock)) +# define lock_lock(lock) glthread_lock_lock (&(lock)) +# define lock_unlock(lock) glthread_lock_unlock (&(lock)) +#elif defined GNULIB_PTHREAD # include <pthread.h> # define lock_define(name) pthread_mutex_t name; # define lock_init(lock) pthread_mutex_init (&(lock), 0) # define lock_fini(lock) pthread_mutex_destroy (&(lock)) -# define __libc_lock_lock(lock) pthread_mutex_lock (&(lock)) -# define __libc_lock_unlock(lock) pthread_mutex_unlock (&(lock)) +# define lock_lock(lock) pthread_mutex_lock (&(lock)) +# define lock_unlock(lock) pthread_mutex_unlock (&(lock)) +#else +# define lock_define(name) +# define lock_init(lock) 0 +# define lock_fini(lock) 0 +# define lock_lock(lock) ((void) 0) +# define lock_unlock(lock) ((void) 0) #endif /* In case that the system doesn't have isblank(). */
--- a/lib/regexec.c +++ b/lib/regexec.c @@ -244,14 +244,14 @@ length = strlen (string); } - __libc_lock_lock (dfa->lock); + lock_lock (dfa->lock); if (preg->no_sub) err = re_search_internal (preg, string, length, start, length, length, 0, NULL, eflags); else err = re_search_internal (preg, string, length, start, length, length, nmatch, pmatch, eflags); - __libc_lock_unlock (dfa->lock); + lock_unlock (dfa->lock); return err != REG_NOERROR; } @@ -430,7 +430,7 @@ else if (BE (last_start < 0 || (range < 0 && start <= last_start), 0)) last_start = 0; - __libc_lock_lock (dfa->lock); + lock_lock (dfa->lock); eflags |= (bufp->not_bol) ? REG_NOTBOL : 0; eflags |= (bufp->not_eol) ? REG_NOTEOL : 0; @@ -494,7 +494,7 @@ } re_free (pmatch); out: - __libc_lock_unlock (dfa->lock); + lock_unlock (dfa->lock); return rval; }
--- a/modules/lock +++ b/modules/lock @@ -11,6 +11,7 @@ configure.ac: gl_LOCK +gl_MODULE_INDICATOR([lock]) Makefile.am: lib_SOURCES += glthread/lock.h glthread/lock.c
--- a/modules/pthread +++ b/modules/pthread @@ -13,6 +13,7 @@ configure.ac: gl_PTHREAD_CHECK +gl_MODULE_INDICATOR([pthread]) Makefile.am: BUILT_SOURCES += $(PTHREAD_H)
--- a/modules/regex +++ b/modules/regex @@ -24,7 +24,6 @@ mbrtowc [test $ac_use_included_regex = yes] mbsinit [test $ac_use_included_regex = yes] nl_langinfo [test $ac_use_included_regex = yes] -pthread [test $ac_use_included_regex = yes] stdbool [test $ac_use_included_regex = yes] stdint [test $ac_use_included_regex = yes] wchar [test $ac_use_included_regex = yes]