summaryrefslogtreecommitdiff
path: root/lib/sqfs/block_processor
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqfs/block_processor')
-rw-r--r--lib/sqfs/block_processor/common.c37
-rw-r--r--lib/sqfs/block_processor/internal.h10
-rw-r--r--lib/sqfs/block_processor/serial.c40
-rw-r--r--lib/sqfs/block_processor/winpthread.c49
4 files changed, 57 insertions, 79 deletions
diff --git a/lib/sqfs/block_processor/common.c b/lib/sqfs/block_processor/common.c
index e2d92c5..c8dbbc2 100644
--- a/lib/sqfs/block_processor/common.c
+++ b/lib/sqfs/block_processor/common.c
@@ -7,43 +7,6 @@
#define SQFS_BUILDING_DLL
#include "internal.h"
-void free_blk_list(sqfs_block_t *list)
-{
- sqfs_block_t *it;
-
- while (list != NULL) {
- it = list;
- list = list->next;
- free(it);
- }
-}
-
-int block_processor_init(sqfs_block_processor_t *proc, 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)
-{
- proc->max_block_size = max_block_size;
- proc->num_workers = num_workers;
- proc->max_backlog = max_backlog;
- proc->cmp = cmp;
- proc->frag_tbl = tbl;
- proc->wr = wr;
-
- memset(&proc->stats, 0, sizeof(proc->stats));
- proc->stats.size = sizeof(proc->stats);
- return 0;
-}
-
-void block_processor_cleanup(sqfs_block_processor_t *proc)
-{
- free_blk_list(proc->queue);
- free_blk_list(proc->done);
- free(proc->blk_current);
- free(proc->frag_block);
- free(proc);
-}
-
int process_completed_block(sqfs_block_processor_t *proc, sqfs_block_t *blk)
{
sqfs_u64 location;
diff --git a/lib/sqfs/block_processor/internal.h b/lib/sqfs/block_processor/internal.h
index a764b2f..45db014 100644
--- a/lib/sqfs/block_processor/internal.h
+++ b/lib/sqfs/block_processor/internal.h
@@ -109,16 +109,6 @@ SQFS_INTERNAL
int process_completed_fragment(sqfs_block_processor_t *proc, sqfs_block_t *frag,
sqfs_block_t **blk_out);
-SQFS_INTERNAL void free_blk_list(sqfs_block_t *list);
-
-SQFS_INTERNAL
-int block_processor_init(sqfs_block_processor_t *proc, 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);
-
-SQFS_INTERNAL void block_processor_cleanup(sqfs_block_processor_t *proc);
-
SQFS_INTERNAL
int block_processor_do_block(sqfs_block_t *block, sqfs_compressor_t *cmp,
sqfs_u8 *scratch, size_t scratch_size);
diff --git a/lib/sqfs/block_processor/serial.c b/lib/sqfs/block_processor/serial.c
index b1e1823..c9ee164 100644
--- a/lib/sqfs/block_processor/serial.c
+++ b/lib/sqfs/block_processor/serial.c
@@ -9,7 +9,11 @@
static void block_processor_destroy(sqfs_object_t *obj)
{
- block_processor_cleanup((sqfs_block_processor_t *)obj);
+ sqfs_block_processor_t *proc = (sqfs_block_processor_t *)obj;
+
+ free(proc->blk_current);
+ free(proc->frag_block);
+ free(proc);
}
sqfs_block_processor_t *sqfs_block_processor_create(size_t max_block_size,
@@ -20,18 +24,17 @@ sqfs_block_processor_t *sqfs_block_processor_create(size_t max_block_size,
sqfs_frag_table_t *tbl)
{
sqfs_block_processor_t *proc;
+ (void)num_workers; (void)max_backlog;
proc = alloc_flex(sizeof(*proc), 1, max_block_size);
-
if (proc == NULL)
return NULL;
- if (block_processor_init(proc, max_block_size, cmp, num_workers,
- max_backlog, wr, tbl)) {
- block_processor_cleanup(proc);
- return NULL;
- }
-
+ proc->max_block_size = max_block_size;
+ proc->cmp = cmp;
+ proc->frag_tbl = tbl;
+ proc->wr = wr;
+ proc->stats.size = sizeof(proc->stats);
((sqfs_object_t *)proc)->destroy = block_processor_destroy;
return proc;
}
@@ -80,18 +83,17 @@ int wait_completed(sqfs_block_processor_t *proc)
int sqfs_block_processor_finish(sqfs_block_processor_t *proc)
{
- if (proc->frag_block != NULL && proc->status == 0) {
- proc->status = block_processor_do_block(proc->frag_block,
- proc->cmp,
- proc->scratch,
- proc->max_block_size);
-
- if (proc->status == 0) {
- proc->status = process_completed_block(proc,
- proc->frag_block);
- }
- }
+ if (proc->frag_block == NULL || proc->status != 0)
+ goto out;
+
+ proc->status = block_processor_do_block(proc->frag_block, proc->cmp,
+ proc->scratch,
+ proc->max_block_size);
+ if (proc->status != 0)
+ goto out;
+ proc->status = process_completed_block(proc, proc->frag_block);
+out:
free(proc->frag_block);
proc->frag_block = NULL;
return proc->status;
diff --git a/lib/sqfs/block_processor/winpthread.c b/lib/sqfs/block_processor/winpthread.c
index 708a2d1..fcbb8b4 100644
--- a/lib/sqfs/block_processor/winpthread.c
+++ b/lib/sqfs/block_processor/winpthread.c
@@ -34,6 +34,17 @@ struct compress_worker_t {
sqfs_u8 scratch[];
};
+static void free_blk_list(sqfs_block_t *list)
+{
+ sqfs_block_t *it;
+
+ while (list != NULL) {
+ it = list;
+ list = list->next;
+ free(it);
+ }
+}
+
static THREAD_TYPE worker_proc(THREAD_ARG arg)
{
compress_worker_t *worker = arg;
@@ -120,7 +131,11 @@ static void block_processor_destroy(sqfs_object_t *obj)
}
DeleteCriticalSection(&proc->mtx);
- block_processor_cleanup(proc);
+ free_blk_list(proc->queue);
+ free_blk_list(proc->done);
+ free(proc->blk_current);
+ free(proc->frag_block);
+ free(proc);
}
sqfs_block_processor_t *sqfs_block_processor_create(size_t max_block_size,
@@ -141,17 +156,19 @@ sqfs_block_processor_t *sqfs_block_processor_create(size_t max_block_size,
if (proc == NULL)
return NULL;
+ proc->max_block_size = max_block_size;
+ proc->num_workers = num_workers;
+ proc->max_backlog = max_backlog;
+ proc->cmp = cmp;
+ proc->frag_tbl = tbl;
+ proc->wr = wr;
+ proc->stats.size = sizeof(proc->stats);
((sqfs_object_t *)obj)->destroy = block_processor_destroy;
InitializeCriticalSection(&proc->mtx);
InitializeConditionVariable(&proc->queue_cond);
InitializeConditionVariable(&proc->done_cond);
- if (block_processor_init(proc, max_block_size, cmp, num_workers,
- max_backlog, wr, tbl)) {
- goto fail;
- }
-
for (i = 0; i < num_workers; ++i) {
proc->workers[i] = alloc_flex(sizeof(compress_worker_t),
1, max_block_size);
@@ -198,7 +215,11 @@ static void block_processor_destroy(sqfs_object_t *obj)
pthread_cond_destroy(&proc->queue_cond);
pthread_mutex_destroy(&proc->mtx);
- block_processor_cleanup(proc);
+ free_blk_list(proc->queue);
+ free_blk_list(proc->done);
+ free(proc->blk_current);
+ free(proc->frag_block);
+ free(proc);
}
sqfs_block_processor_t *sqfs_block_processor_create(size_t max_block_size,
@@ -225,11 +246,13 @@ sqfs_block_processor_t *sqfs_block_processor_create(size_t max_block_size,
proc->mtx = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;
proc->queue_cond = (pthread_cond_t)PTHREAD_COND_INITIALIZER;
proc->done_cond = (pthread_cond_t)PTHREAD_COND_INITIALIZER;
-
- if (block_processor_init(proc, max_block_size, cmp, num_workers,
- max_backlog, wr, tbl)) {
- goto fail_init;
- }
+ proc->max_block_size = max_block_size;
+ proc->num_workers = num_workers;
+ proc->max_backlog = max_backlog;
+ proc->cmp = cmp;
+ proc->frag_tbl = tbl;
+ proc->wr = wr;
+ proc->stats.size = sizeof(proc->stats);
for (i = 0; i < num_workers; ++i) {
proc->workers[i] = alloc_flex(sizeof(compress_worker_t),
@@ -283,7 +306,7 @@ fail_init:
pthread_cond_destroy(&proc->done_cond);
pthread_cond_destroy(&proc->queue_cond);
pthread_mutex_destroy(&proc->mtx);
- block_processor_cleanup(proc);
+ free(proc);
return NULL;
}
#endif