ranches@freebsd.org> List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mp X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: f1b50f2cb0dbaf4c036fb8123b075ad8329559e4 Auto-Submitted: auto-generated Date: Mon, 15 Dec 2025 22:50:29 +0000 Message-Id: <694090b5.46876.4f4fd4ba@gitrepo.freebsd.org> The branch stable/13 has been updated by mp: URL: https://cgit.FreeBSD.org/src/commit/?id=f1b50f2cb0dbaf4c036fb8123b075ad8329559e4 commit f1b50f2cb0dbaf4c036fb8123b075ad8329559e4 Author: Mark Peek AuthorDate: 2025-12-01 20:50:24 +0000 Commit: Mark Peek CommitDate: 2025-12-15 22:50:10 +0000 ctfmerge: fix segfault when building on macOS The barrier code was using semaphores which have been deprecated in macOS and not working at all, causing a race condition. Since macOS does not have pthread_barrier_*(), this change uses a condition variable instead. PR: 290958 Reported by: wosch Reviewed by: imp, markj Differential Revision: https://reviews.freebsd.org/D54018 (cherry picked from commit 732b4aa05d78ca6831d02e67a43f34ad104f4f01) --- cddl/contrib/opensolaris/tools/ctf/cvt/barrier.c | 26 +++--------------------- cddl/contrib/opensolaris/tools/ctf/cvt/barrier.h | 9 ++------ 2 files changed, 5 insertions(+), 30 deletions(-) diff --git a/cddl/contrib/opensolaris/tools/ctf/cvt/barrier.c b/cddl/contrib/opensolaris/tools/ctf/cvt/barrier.c index c0719620dbde..e1f54e994ce3 100644 --- a/cddl/contrib/opensolaris/tools/ctf/cvt/barrier.c +++ b/cddl/contrib/opensolaris/tools/ctf/cvt/barrier.c @@ -38,9 +38,6 @@ */ #include -#ifdef illumos -#include -#endif #include #include "barrier.h" @@ -49,12 +46,7 @@ void barrier_init(barrier_t *bar, int nthreads) { pthread_mutex_init(&bar->bar_lock, NULL); -#ifdef illumos - sema_init(&bar->bar_sem, 0, USYNC_THREAD, NULL); -#else - sem_init(&bar->bar_sem, 0, 0); -#endif - + pthread_cond_init(&bar->bar_cv, NULL); bar->bar_numin = 0; bar->bar_nthr = nthreads; } @@ -65,26 +57,14 @@ barrier_wait(barrier_t *bar) pthread_mutex_lock(&bar->bar_lock); if (++bar->bar_numin < bar->bar_nthr) { + pthread_cond_wait(&bar->bar_cv, &bar->bar_lock); pthread_mutex_unlock(&bar->bar_lock); -#ifdef illumos - sema_wait(&bar->bar_sem); -#else - sem_wait(&bar->bar_sem); -#endif return (0); - } else { - int i; - /* reset for next use */ bar->bar_numin = 0; - for (i = 1; i < bar->bar_nthr; i++) -#ifdef illumos - sema_post(&bar->bar_sem); -#else - sem_post(&bar->bar_sem); -#endif + pthread_cond_broadcast(&bar->bar_cv); pthread_mutex_unlock(&bar->bar_lock); return (1); diff --git a/cddl/contrib/opensolaris/tools/ctf/cvt/barrier.h b/cddl/contrib/opensolaris/tools/ctf/cvt/barrier.h index babf2e64e33f..138386f8ed46 100644 --- a/cddl/contrib/opensolaris/tools/ctf/cvt/barrier.h +++ b/cddl/contrib/opensolaris/tools/ctf/cvt/barrier.h @@ -33,12 +33,7 @@ * APIs for the barrier synchronization primitive. */ -#ifdef illumos -#include -#else -#include -typedef sem_t sema_t; -#endif +#include #ifdef __cplusplus extern "C" { @@ -48,7 +43,7 @@ typedef struct barrier { pthread_mutex_t bar_lock; /* protects bar_numin */ int bar_numin; /* current number of waiters */ - sema_t bar_sem; /* where everyone waits */ + pthread_cond_t bar_cv; /* where everyone waits */ int bar_nthr; /* # of waiters to trigger release */ } barrier_t;