From: Paul Eggert Date: Wed, 29 May 2013 17:24:17 +0000 (-0700) Subject: regex: adapt to locking regime instead of depending on pthread X-Git-Tag: v0.1~118 X-Git-Url: http://erislabs.net/gitweb/?p=gnulib.git;a=commitdiff_plain;h=55ba71f47850fbd870cb08bac1cf992f1368295e 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 and by Mats Erik Andersson in . * 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. --- diff --git a/ChangeLog b/ChangeLog index aa74ea4f3..8097562ed 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2013-05-29 Paul Eggert + + 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 + + and by Mats Erik Andersson in + . + * 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 getgroups: document portability issues diff --git a/lib/regex_internal.h b/lib/regex_internal.h index 63a9979fd..0f917e66e 100644 --- a/lib/regex_internal.h +++ b/lib/regex_internal.h @@ -33,24 +33,33 @@ #include #include -#if defined _LIBC +#ifdef _LIBC # include -#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 # 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(). */ diff --git a/lib/regexec.c b/lib/regexec.c index 114287ec1..21d14ad14 100644 --- a/lib/regexec.c +++ b/lib/regexec.c @@ -244,14 +244,14 @@ regexec (preg, string, nmatch, pmatch, eflags) 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 @@ re_search_stub (struct re_pattern_buffer *bufp, 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_search_stub (struct re_pattern_buffer *bufp, } re_free (pmatch); out: - __libc_lock_unlock (dfa->lock); + lock_unlock (dfa->lock); return rval; } diff --git a/modules/lock b/modules/lock index f7e4c9a9b..3377915fc 100644 --- a/modules/lock +++ b/modules/lock @@ -11,6 +11,7 @@ threadlib configure.ac: gl_LOCK +gl_MODULE_INDICATOR([lock]) Makefile.am: lib_SOURCES += glthread/lock.h glthread/lock.c diff --git a/modules/pthread b/modules/pthread index cd4985258..e583929e1 100644 --- a/modules/pthread +++ b/modules/pthread @@ -13,6 +13,7 @@ time configure.ac: gl_PTHREAD_CHECK +gl_MODULE_INDICATOR([pthread]) Makefile.am: BUILT_SOURCES += $(PTHREAD_H) diff --git a/modules/regex b/modules/regex index 2dbb777d6..8f5eda061 100644 --- a/modules/regex +++ b/modules/regex @@ -24,7 +24,6 @@ memmove [test $ac_use_included_regex = yes] 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]