aboutsummaryrefslogtreecommitdiff
path: root/lib/sqfs/block_processor/winpthread.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2021-01-06 14:24:15 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2021-01-19 04:03:37 +0100
commit405d133e7f0dc0f92f54f08ef6078208028448a1 (patch)
treeb0a5ffca40f50f5c6a1c7e322434e9c0d4936a0e /lib/sqfs/block_processor/winpthread.c
parentfe70d543c448ccb1adfb9a5d948820dc2c9d1e61 (diff)
libsqfs: Add a sqfs_block_processor_create_ex function
This function creates a block processor from a structure describing it. A stub implementation for the old sqfs_block_processor_create is added that simply sets up such a struct and forwards the call. The current version of the description struct only contains the exact same parameters and a size field at the beginning. This approach is supposed to make extending the range of parameters easier without breaking ABI compatibillity. Currently already planned are: - Adding a sqfs_file_t pointer to double-check when deduplicating fragments. - When the scanning code reaches a usable state, add the abillity to pass scanned fragment data, so the block processor can be used for appending to an existing image. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs/block_processor/winpthread.c')
-rw-r--r--lib/sqfs/block_processor/winpthread.c46
1 files changed, 26 insertions, 20 deletions
diff --git a/lib/sqfs/block_processor/winpthread.c b/lib/sqfs/block_processor/winpthread.c
index 3531a3b..c3e3d13 100644
--- a/lib/sqfs/block_processor/winpthread.c
+++ b/lib/sqfs/block_processor/winpthread.c
@@ -393,35 +393,34 @@ static int block_processor_sync(sqfs_block_processor_t *proc)
return append_to_work_queue(proc, NULL);
}
-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,
- sqfs_block_writer_t *wr,
- sqfs_frag_table_t *tbl)
+int sqfs_block_processor_create_ex(const sqfs_block_processor_desc_t *desc,
+ sqfs_block_processor_t **out)
{
thread_pool_processor_t *proc;
+ unsigned int i, num_workers;
sigset_t oldset;
- unsigned int i;
int ret;
- if (num_workers < 1)
- num_workers = 1;
+ if (desc->size != sizeof(sqfs_block_processor_desc_t))
+ return SQFS_ERROR_ARG_INVALID;
+
+ num_workers = desc->num_workers < 1 ? 1 : desc->num_workers;
proc = alloc_flex(sizeof(*proc),
sizeof(proc->workers[0]), num_workers);
if (proc == NULL)
- return NULL;
+ return SQFS_ERROR_ALLOC;
- if (block_processor_init(&proc->base, max_block_size, cmp, wr, tbl)) {
+ ret = block_processor_init(&proc->base, desc);
+ if (ret != 0) {
free(proc);
- return NULL;
+ return ret;
}
proc->base.sync = block_processor_sync;
proc->base.append_to_work_queue = append_to_work_queue;
proc->num_workers = num_workers;
- proc->max_backlog = max_backlog;
+ proc->max_backlog = desc->max_backlog;
((sqfs_object_t *)proc)->destroy = block_processor_destroy;
MUTEX_INIT(&proc->mtx);
@@ -432,27 +431,34 @@ sqfs_block_processor_t *sqfs_block_processor_create(size_t max_block_size,
for (i = 0; i < num_workers; ++i) {
proc->workers[i] = alloc_flex(sizeof(compress_worker_t),
- 1, max_block_size);
+ 1, desc->max_block_size);
- if (proc->workers[i] == NULL)
+ if (proc->workers[i] == NULL) {
+ ret = SQFS_ERROR_ALLOC;
goto fail;
+ }
proc->workers[i]->shared = proc;
- proc->workers[i]->cmp = sqfs_copy(cmp);
+ proc->workers[i]->cmp = sqfs_copy(desc->cmp);
- if (proc->workers[i]->cmp == NULL)
+ if (proc->workers[i]->cmp == NULL) {
+ ret = SQFS_ERROR_ALLOC;
goto fail;
+ }
ret = THREAD_CREATE(&proc->workers[i]->thread,
worker_proc, proc->workers[i]);
- if (ret != 0)
+ if (ret != 0) {
+ ret = SQFS_ERROR_INTERNAL;
goto fail;
+ }
}
SIGNAL_ENABLE(&oldset);
- return (sqfs_block_processor_t *)proc;
+ *out = (sqfs_block_processor_t *)proc;
+ return 0;
fail:
SIGNAL_ENABLE(&oldset);
block_processor_destroy((sqfs_object_t *)proc);
- return NULL;
+ return ret;
}