diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-09-10 13:08:26 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-09-10 13:08:26 +0200 |
commit | 1fe6b2aa4158516f9c6cf5751cc68aafef1af620 (patch) | |
tree | 2047e37b6101f35c5dd55c59b885be22fe570407 /lib/sqfs | |
parent | 49c2c4a8c8a8eb32a7d5fdbf4b1eba24bb23efe7 (diff) |
Make the thread pool queue backlog user configurable
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs')
-rw-r--r-- | lib/sqfs/block_processor.c | 2 | ||||
-rw-r--r-- | lib/sqfs/block_processor_parallel.c | 7 |
2 files changed, 6 insertions, 3 deletions
diff --git a/lib/sqfs/block_processor.c b/lib/sqfs/block_processor.c index 3fa37fd..ef71f9e 100644 --- a/lib/sqfs/block_processor.c +++ b/lib/sqfs/block_processor.c @@ -27,11 +27,13 @@ struct sqfs_block_processor_t { sqfs_block_processor_t *sqfs_block_processor_create(size_t max_block_size, sqfs_compressor_t *cmp, unsigned int num_workers, + size_t max_backlog, void *user, sqfs_block_cb callback) { sqfs_block_processor_t *proc; (void)num_workers; + (void)max_backlog; proc = alloc_flex(sizeof(*proc), 1, max_block_size); diff --git a/lib/sqfs/block_processor_parallel.c b/lib/sqfs/block_processor_parallel.c index 05c07f1..a63135a 100644 --- a/lib/sqfs/block_processor_parallel.c +++ b/lib/sqfs/block_processor_parallel.c @@ -16,8 +16,6 @@ #include <string.h> #include <stdlib.h> -#define MAX_BACKLOG_FACTOR (10) - typedef struct { sqfs_block_processor_t *shared; sqfs_compressor_t *cmp; @@ -46,6 +44,7 @@ struct sqfs_block_processor_t { sqfs_block_cb cb; void *user; int status; + size_t max_backlog; /* used only by workers */ size_t max_block_size; @@ -117,6 +116,7 @@ static void *worker_proc(void *arg) sqfs_block_processor_t *sqfs_block_processor_create(size_t max_block_size, sqfs_compressor_t *cmp, unsigned int num_workers, + size_t max_backlog, void *user, sqfs_block_cb callback) { @@ -136,6 +136,7 @@ sqfs_block_processor_t *sqfs_block_processor_create(size_t max_block_size, proc->cb = callback; proc->user = user; proc->num_workers = num_workers; + proc->max_backlog = max_backlog; if (pthread_mutex_init(&proc->mtx, NULL)) goto fail_free; @@ -274,7 +275,7 @@ int sqfs_block_processor_enqueue(sqfs_block_processor_t *proc, (block->flags & SQFS_BLK_DONT_CHECKSUM)) { store_completed_block(proc, block); } else { - while (proc->backlog > proc->num_workers * MAX_BACKLOG_FACTOR) + while (proc->backlog > proc->max_backlog) pthread_cond_wait(&proc->done_cond, &proc->mtx); if (proc->queue_last == NULL) { |