aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-10 13:08:26 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-10 13:08:26 +0200
commit1fe6b2aa4158516f9c6cf5751cc68aafef1af620 (patch)
tree2047e37b6101f35c5dd55c59b885be22fe570407 /lib
parent49c2c4a8c8a8eb32a7d5fdbf4b1eba24bb23efe7 (diff)
Make the thread pool queue backlog user configurable
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib')
-rw-r--r--lib/sqfs/block_processor.c2
-rw-r--r--lib/sqfs/block_processor_parallel.c7
-rw-r--r--lib/sqfshelper/data_writer.c4
3 files changed, 8 insertions, 5 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) {
diff --git a/lib/sqfshelper/data_writer.c b/lib/sqfshelper/data_writer.c
index 463eb60..d6a935b 100644
--- a/lib/sqfshelper/data_writer.c
+++ b/lib/sqfshelper/data_writer.c
@@ -452,7 +452,7 @@ int write_data_from_fd_condensed(data_writer_t *data, file_info_t *fi,
data_writer_t *data_writer_create(sqfs_super_t *super, sqfs_compressor_t *cmp,
sqfs_file_t *file, size_t devblksize,
- unsigned int num_jobs)
+ unsigned int num_jobs, size_t max_backlog)
{
data_writer_t *data = calloc(1, sizeof(*data));
@@ -462,7 +462,7 @@ data_writer_t *data_writer_create(sqfs_super_t *super, sqfs_compressor_t *cmp,
}
data->proc = sqfs_block_processor_create(super->block_size, cmp,
- num_jobs, data,
+ num_jobs, max_backlog, data,
block_callback);
data->cmp = cmp;
data->super = super;