From e3d8fe4854a7ef7ff0637688cda9e65feb680122 Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Thu, 15 Oct 2026 12:37:10 +0300 Subject: Replace the writer spin lock with a blocking mutex term_write_begin spun on an atomic sequence word. A waiter burned CPU, and with no priority inheritance a SCHED_FIFO waiter could starve a preempted holder on the same CPU. The writer section is now a pthread mutex with PTHREAD_PRIO_INHERIT where the platform has it, and an SRWLOCK on Windows. Re-entry on the owning thread still only counts the depth. The platform wrapper (init, lock, unlock, destroy) is in compat.h. term_new initializes the mutex, and term_free destroys it. Meson links the thread library into the core, term_dep, and term_internal_dep. The README, term.h, and the amalgamation note say that POSIX needs -pthread. Tests: the feed and snapshot thread test now checks the final screen and history against a serial reference. A new test checks that term_lock nests and that another thread waits for the last term_unlock. Co-Authored-By: Claude Haiku 5.5 --- meson.build | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'meson.build') diff --git a/meson.build b/meson.build index d23c0b4..fa450f9 100644 --- a/meson.build +++ b/meson.build @@ -15,6 +15,8 @@ project('term', 'c', cc = meson.get_compiler('c') m_dep = cc.find_library('m', required: false) +# The writer lock is a pthread mutex on POSIX and an SRWLOCK on Windows. +thread_dep = dependency('threads') if get_option('arch_flag') != '' add_project_arguments(get_option('arch_flag'), language: 'c') endif @@ -29,7 +31,7 @@ subdir('src') term_dep = declare_dependency( include_directories: term_inc, link_with: term_lib.get_static_lib(), - dependencies: m_dep, + dependencies: [m_dep, thread_dep], ) meson.override_dependency('term', term_dep) @@ -37,7 +39,7 @@ meson.override_dependency('term', term_dep) term_internal_dep = declare_dependency( include_directories: [term_inc, term_private_inc], link_with: term_lib.get_static_lib(), - dependencies: m_dep, + dependencies: [m_dep, thread_dep], ) # The short forms of term.h that the term tests use. A host project can use -- cgit v1.2.3