[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: pthread fails with OpenBSD 4.6 and 5.0.
From: |
Paul Eggert |
Subject: |
Re: pthread fails with OpenBSD 4.6 and 5.0. |
Date: |
Wed, 29 May 2013 10:27:02 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130311 Thunderbird/17.0.4 |
Ludovic Courtès reported a similar problem, and I had the following
patch in my pipeline. Could you please try it? I've pushed it into
gnulib. I've tested it only cursorily. Thanks.
>From 7e43f9d5c2e972161b1a1b272d025dc497b36578 Mon Sep 17 00:00:00 2001
From: Paul Eggert <address@hidden>
Date: Wed, 29 May 2013 10:24:17 -0700
Subject: [PATCH] regex: adapt to locking regime instead of depending on
pthread
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
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 | 16 ++++++++++++++++
lib/regex_internal.h | 29 +++++++++++++++++++----------
lib/regexec.c | 8 ++++----
modules/lock | 1 +
modules/pthread | 1 +
modules/regex | 1 -
6 files changed, 41 insertions(+), 15 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index aa74ea4..8097562 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2013-05-29 Paul Eggert <address@hidden>
+
+ 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 <address@hidden>
getgroups: document portability issues
diff --git a/lib/regex_internal.h b/lib/regex_internal.h
index 63a9979..0f917e6 100644
--- 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(). */
diff --git a/lib/regexec.c b/lib/regexec.c
index 114287e..21d14ad 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 f7e4c9a..3377915 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 cd49852..e583929 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 2dbb777..8f5eda0 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]
--
1.7.11.7