From 1a28e35c62d8f85a73adf6b669f4b61a276a31a9 Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Thu, 28 Dec 2023 04:55:50 -0800 Subject: [PATCH] Use good locks in dlmalloc Using mere spin locks causes runitd.com to go painstakingly slow on NetBSD for reasons that aren't clear yet. --- third_party/dlmalloc/dlmalloc.c | 1 + third_party/dlmalloc/locks.inc | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/third_party/dlmalloc/dlmalloc.c b/third_party/dlmalloc/dlmalloc.c index 356f72b04..5b2ae8891 100644 --- a/third_party/dlmalloc/dlmalloc.c +++ b/third_party/dlmalloc/dlmalloc.c @@ -32,6 +32,7 @@ #define HAVE_MREMAP 0 #define HAVE_MORECORE 0 #define USE_LOCKS 2 +#define USE_SPIN_LOCKS 0 #define MORECORE_CONTIGUOUS 0 #define MALLOC_INSPECT_ALL 1 #define ABORT_ON_ASSERT_FAILURE 0 diff --git a/third_party/dlmalloc/locks.inc b/third_party/dlmalloc/locks.inc index 8eab25ece..b74887916 100644 --- a/third_party/dlmalloc/locks.inc +++ b/third_party/dlmalloc/locks.inc @@ -29,7 +29,7 @@ */ -#ifdef USE_SPIN_LOCKS +#if USE_SPIN_LOCKS #define MLOCK_T atomic_uint @@ -62,11 +62,13 @@ static int malloc_wipe(MLOCK_T *lk) { } static int malloc_lock(MLOCK_T *lk) { + if (!__threaded) return 0; nsync_mu_lock(lk); return 0; } static int malloc_unlock(MLOCK_T *lk) { + if (!__threaded) return 0; nsync_mu_unlock(lk); return 0; }