aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBernd Schubert <bernd@bsbernd.com>2025-08-18 22:37:11 +0200
committerBernd Schubert <bernd@bsbernd.com>2025-08-22 16:57:26 +0200
commitbd8d8cdda9a5f520b7decfe98fafe540992ecb87 (patch)
tree44f4947c74e1279b4e480c7976aad0ad68882231 /lib
parent8b8ce5a8242e78db4f1d22437d8e1f015d71765f (diff)
downloadlibfuse-bd8d8cdda9a5f520b7decfe98fafe540992ecb87.tar.gz
io-uring startup: Fix spinning and variable read
Reported-by: lixianming <lixianming.19951001@bytedance.com> Closes: https://github.com/libfuse/libfuse/pull/1317 Signed-off-by: Bernd Schubert <bernd@bsbernd.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/fuse_uring.c25
1 files changed, 15 insertions, 10 deletions
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;