Fix io_flush_thread() to wait for in-flight writer tasks before returning

This commit is contained in:
Andrea Mazzoleni 2026-08-17 18:13:56 +02:00
parent a1a3315824
commit e9f9603207
2 changed files with 8 additions and 2 deletions

View file

@ -348,6 +348,8 @@ static struct snapraid_task* io_writer_step(struct snapraid_worker* worker, int
if (error_index >= 0 && error_index < IO_WRITER_ERROR_MAX)
++io->writer_error[error_index];
worker->busy = 0;
while (1) {
unsigned next_index;
@ -368,6 +370,8 @@ static struct snapraid_task* io_writer_step(struct snapraid_worker* worker, int
worker->index = next_index;
task = &worker->task_map[worker->index];
worker->busy = 1;
/* if the just completed task is at this index */
if (done_index == waiting_index) {
/* notify the IO that a new write is complete */
@ -545,8 +549,8 @@ static void io_flush_thread(struct snapraid_io* io)
/* get the next pending task */
unsigned next_index = (worker->index + 1) % io->io_max;
/* if the queue of pending tasks is not empty */
if (next_index != io->writer_index) {
/* if a task is in progress or the queue is not empty */
if (worker->busy || next_index != io->writer_index) {
all_done = 0;
break;
}
@ -873,6 +877,7 @@ static void io_start_thread(struct snapraid_io* io,
struct snapraid_worker* worker = &io->writer_map[i];
worker->index = io->io_max - 1;
worker->busy = 0;
thread_create(&worker->thread, io_writer_thread, worker);
}

View file

@ -74,6 +74,7 @@ struct snapraid_task {
struct snapraid_worker {
#if HAVE_THREAD
thread_id_t thread; /**< Thread context for the worker. */
int busy; /**< A task is currently being processed. */
#endif
/**