From bd8d8cdda9a5f520b7decfe98fafe540992ecb87 Mon Sep 17 00:00:00 2001 From: Bernd Schubert Date: Mon, 18 Aug 2025 22:37:11 +0200 Subject: io-uring startup: Fix spinning and variable read Reported-by: lixianming Closes: https://github.com/libfuse/libfuse/pull/1317 Signed-off-by: Bernd Schubert --- lib/fuse_uring.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'lib/fuse_uring.c') diff --git a/lib/fuse_uring.c b/lib/fuse_uring.c index 985c817..a835ea1 100644 --- a/lib/fuse_uring.c +++ b/lib/fuse_uring.c @@ -384,6 +384,8 @@ static void fuse_session_destruct_uring(struct fuse_ring_pool *fuse_ring) } free(fuse_ring->queues); + pthread_cond_destroy(&fuse_ring->thread_start_cond); + pthread_mutex_destroy(&fuse_ring->thread_start_mutex); free(fuse_ring); } @@ -491,6 +493,10 @@ static struct fuse_ring_pool *fuse_create_ring(struct fuse_session *se) queue->ring_pool = fuse_ring; } + pthread_cond_init(&fuse_ring->thread_start_cond, NULL); + pthread_mutex_init(&fuse_ring->thread_start_mutex, NULL); + sem_init(&fuse_ring->init_sem, 0, 0); + return fuse_ring; err: @@ -787,18 +793,17 @@ int fuse_uring_start(struct fuse_session *se) if (err) goto err; - while (fuse_ring->started_threads < fuse_ring->nr_queues) { - /* Wait for all threads to start */ - if (fuse_ring->failed_threads != 0) { - err = -EADDRNOTAVAIL; - goto err; - } - } + /* + * Wait for all threads to start or to fail + */ + pthread_mutex_lock(&fuse_ring->thread_start_mutex); + while (fuse_ring->started_threads < fuse_ring->nr_queues) + pthread_cond_wait(&fuse_ring->thread_start_cond, + &fuse_ring->thread_start_mutex); - if (fuse_ring->failed_threads != 0) { + if (fuse_ring->failed_threads != 0) err = -EADDRNOTAVAIL; - goto err; - } + pthread_mutex_unlock(&fuse_ring->thread_start_mutex); err: return err; -- cgit v1.2.3