From 451323135e56bc52945da72e2bf9f6b0992e35b3 Mon Sep 17 00:00:00 2001 From: dlg <> Date: Mon, 4 Aug 2025 01:44:33 +0000 Subject: replace the flockfile backend with a per FILE recursive mutex. the flockfile implementation in thread/rthread_file.c used an external lock, and associated it with the relevant FILE * as needed. this isn't great for a lot of reasons, complexity being the big one, but the straw that broke the camels back is that it uses a single spinlock to coordinate all of this, which in turn generates a lot of sched_yield syscalls. this avoids all the code complexity and the spinlock by just embedding a small __rctmx in every FILE. tested by and ok tb@ jca@ ok claudio@ --- src/lib/libc/include/thread_private.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/lib/libc/include/thread_private.h b/src/lib/libc/include/thread_private.h index 7e7c716e2a..3e1dbcdf6e 100644 --- a/src/lib/libc/include/thread_private.h +++ b/src/lib/libc/include/thread_private.h @@ -1,4 +1,4 @@ -/* $OpenBSD: thread_private.h,v 1.39 2025/07/16 16:22:58 deraadt Exp $ */ +/* $OpenBSD: thread_private.h,v 1.40 2025/08/04 01:44:33 dlg Exp $ */ /* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman */ @@ -383,6 +383,12 @@ struct __rcmtx { unsigned int depth; }; +#define __RCMTX_INITIALIZER() { \ + .owner = NULL, \ + .mtx = __CMTX_INITIALIZER(), \ + .depth = 0, \ +} + struct pthread_mutex_attr { int ma_type; int ma_protocol; -- cgit v1.2.3-55-g6feb