From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 0F6751F601 for ; Sat, 3 Sep 2022 11:18:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1662203909; bh=ktJzafd+lmNydsMSMLMKh8ZGNxYb+bCGELTOHm4wM7c=; h=From:To:Subject:Date:In-Reply-To:References:From; b=NEugZy0hqTe2mFqAw6Tnw8Ug1pdrPJ2rHo02OftU+8509AxH1y6Sry1AJvJX3qHYB DbKRgtjyJA3528xK4TXNBS4JrjjYMbS7sQ4L8oiAb1q5bsxCfCeor79s89VuoF32Da 1NYdiPbkb+wCUhSWhny4Q96n+hdYypka1yYd1phk= From: Eric Wong To: mwrap-perl@80x24.org Subject: [PATCH 2/4] cleanup some FreeBSD-related workarounds Date: Sat, 3 Sep 2022 11:18:26 +0000 Message-Id: <20220903111828.2316808-3-mwrap-perl@80x24.org> In-Reply-To: <20220903111828.2316808-1-mwrap-perl@80x24.org> References: <20220903111828.2316808-1-mwrap-perl@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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);