From: Eric Wong <mwrap-perl@80x24.org>
To: mwrap-perl@80x24.org
Subject: [PATCH 2/4] cleanup some FreeBSD-related workarounds
Date: Sat, 3 Sep 2022 11:18:26 +0000 [thread overview]
Message-ID: <20220903111828.2316808-3-mwrap-perl@80x24.org> (raw)
In-Reply-To: <20220903111828.2316808-1-mwrap-perl@80x24.org>
This is to keep up with the Ruby version.
---
Mwrap.xs | 35 +++++++++++++++++++++--------------
1 file changed, 21 insertions(+), 14 deletions(-)
diff --git a/Mwrap.xs b/Mwrap.xs
index e888a1c..3392fee 100644
--- a/Mwrap.xs
+++ b/Mwrap.xs
@@ -84,9 +84,16 @@ union padded_mutex {
/* a round-robin pool of mutexes */
#define MUTEX_NR (1 << 6)
#define MUTEX_MASK (MUTEX_NR - 1)
+#ifdef __FreeBSD__
+# define STATIC_MTX_INIT_OK (0)
+#else /* only tested on Linux + glibc */
+# define STATIC_MTX_INIT_OK (1)
+#endif
static size_t mutex_i;
static union padded_mutex mutexes[MUTEX_NR] = {
+#if STATIC_MTX_INIT_OK
[0 ... (MUTEX_NR-1)].mtx = PTHREAD_MUTEX_INITIALIZER
+#endif
};
static pthread_mutex_t *mutex_assign(void)
@@ -106,12 +113,11 @@ __attribute__((constructor)) static void resolve_malloc(void)
++locating;
-#ifdef __FreeBSD__
/*
* PTHREAD_MUTEX_INITIALIZER on FreeBSD means lazy initialization,
* which happens at pthread_mutex_lock, and that calls calloc
*/
- {
+ if (!STATIC_MTX_INIT_OK) {
size_t i;
for (i = 0; i < MUTEX_NR; i++) {
@@ -124,19 +130,20 @@ __attribute__((constructor)) static void resolve_malloc(void)
/* initialize mutexes used by urcu-bp */
rcu_read_lock();
rcu_read_unlock();
+#ifndef __FreeBSD__
+ } else {
+ if (!real_malloc) {
+ resolving_malloc = 1;
+ real_malloc = dlsym(RTLD_NEXT, "malloc");
+ }
+ real_free = dlsym(RTLD_NEXT, "free");
+ if (!real_malloc || !real_free) {
+ fprintf(stderr, "missing malloc/aligned_alloc/free\n"
+ "\t%p %p\n", real_malloc, real_free);
+ _exit(1);
+ }
}
-#else /* !FreeBSD (tested on GNU/Linux) */
- if (!real_malloc) {
- resolving_malloc = 1;
- real_malloc = dlsym(RTLD_NEXT, "malloc");
- }
- real_free = dlsym(RTLD_NEXT, "free");
- if (!real_malloc || !real_free) {
- fprintf(stderr, "missing malloc/aligned_alloc/free\n"
- "\t%p %p\n", real_malloc, real_free);
- _exit(1);
- }
-#endif /* !FreeBSD */
+#endif /* !__FreeBSD__ */
err = pthread_atfork(call_rcu_before_fork,
call_rcu_after_fork_parent,
call_rcu_after_fork_child);
next prev parent reply other threads:[~2022-09-03 11:18 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-03 11:18 [PATCH 0/4] various cleanups and fixes from the Ruby side Eric Wong
2022-09-03 11:18 ` [PATCH 1/4] favor _Thread_local under C11 Eric Wong
2022-09-03 11:18 ` Eric Wong [this message]
2022-09-04 7:01 ` [PATCH 2/4] cleanup some FreeBSD-related workarounds Eric Wong
2022-09-03 11:18 ` [PATCH 3/4] use macro to quiet uninitialized and unused variable warnings Eric Wong
2022-09-03 11:18 ` [PATCH 4/4] workaround breakage from urcu v0.11.4 Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220903111828.2316808-3-mwrap-perl@80x24.org \
--to=mwrap-perl@80x24.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mwrap-perl.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).