diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-09-24 01:55:08 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-09-24 01:55:08 +0200 |
commit | 87d577a66eb3b1aaca91c4841445cccaf151ee81 (patch) | |
tree | a18d674c9949bc75db584218ab2fa227a2f2b752 /lib/sqfs/blk_proc/pthread.c | |
parent | 824423a9d2395514101cb837c2ede5473cf106ce (diff) |
Process completed blocks one-by-one
This commit makes sure the block processor enqueue function dequeues
at most a single block which it dispatches.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs/blk_proc/pthread.c')
-rw-r--r-- | lib/sqfs/blk_proc/pthread.c | 51 |
1 files changed, 31 insertions, 20 deletions
diff --git a/lib/sqfs/blk_proc/pthread.c b/lib/sqfs/blk_proc/pthread.c index fb83bbe..ee73e52 100644 --- a/lib/sqfs/blk_proc/pthread.c +++ b/lib/sqfs/blk_proc/pthread.c @@ -200,7 +200,6 @@ void sqfs_block_processor_destroy(sqfs_block_processor_t *proc) int sqfs_block_processor_enqueue(sqfs_block_processor_t *proc, sqfs_block_t *block) { - sqfs_block_t *queue = NULL, *it, *prev; int status; pthread_mutex_lock(&proc->mtx); @@ -236,25 +235,30 @@ int sqfs_block_processor_enqueue(sqfs_block_processor_t *proc, proc->backlog += 1; } - it = proc->done; - prev = NULL; - - while (it != NULL && it->sequence_number == proc->dequeue_id) { - prev = it; - it = it->next; + if (proc->done != NULL && + proc->done->sequence_number == proc->dequeue_id) { + block = proc->done; + proc->done = proc->done->next; proc->dequeue_id += 1; - } - - if (prev != NULL) { - queue = proc->done; - prev->next = NULL; - proc->done = it; + } else { + block = NULL; } pthread_cond_broadcast(&proc->queue_cond); pthread_mutex_unlock(&proc->mtx); - return process_completed_blocks(proc, queue); + if (block == NULL) + return 0; + + status = process_completed_block(proc, block); + if (status != 0) { + pthread_mutex_lock(&proc->mtx); + proc->status = status; + goto fail; + } + + free(block); + return 0; fail: pthread_mutex_unlock(&proc->mtx); free(block); @@ -287,12 +291,19 @@ int sqfs_block_processor_finish(sqfs_block_processor_t *proc) proc->done = NULL; pthread_mutex_unlock(&proc->mtx); - status = process_completed_blocks(proc, queue); - if (status != 0) { - pthread_mutex_lock(&proc->mtx); - proc->status = status; - pthread_cond_broadcast(&proc->queue_cond); - goto fail; + while (queue != NULL) { + it = queue; + queue = queue->next; + it->next = NULL; + + status = process_completed_block(proc, it); + free(it); + if (status != 0) { + pthread_mutex_lock(&proc->mtx); + proc->status = status; + pthread_cond_broadcast(&proc->queue_cond); + goto fail; + } } return 0; |