regex: adapt to locking regime instead of depending on pthread
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 29 May 2013 17:24:17 +0000 (10:24 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 29 May 2013 17:24:38 +0000 (10:24 -0700)
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.

ChangeLog
lib/regex_internal.h
lib/regexec.c
modules/lock
modules/pthread
modules/regex

index aa74ea4..8097562 100644 (file)
--- 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
index 63a9979..0f917e6 100644 (file)
 #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().  */
index 114287e..21d14ad 100644 (file)
@@ -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;
 }
 
index f7e4c9a..3377915 100644 (file)
@@ -11,6 +11,7 @@ threadlib
 
 configure.ac:
 gl_LOCK
+gl_MODULE_INDICATOR([lock])
 
 Makefile.am:
 lib_SOURCES += glthread/lock.h glthread/lock.c
index cd49852..e583929 100644 (file)
@@ -13,6 +13,7 @@ time
 
 configure.ac:
 gl_PTHREAD_CHECK
+gl_MODULE_INDICATOR([pthread])
 
 Makefile.am:
 BUILT_SOURCES += $(PTHREAD_H)
index 2dbb777..8f5eda0 100644 (file)
@@ -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]