aboutsummaryrefslogtreecommitdiff
path: root/lib/sqfs
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-05 18:22:28 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-05 18:22:28 +0200
commitf92cf3b98f51d355c92900f1d316b141b2b9d4fd (patch)
tree87d86e178288ef4c70831ac3b6ae977786fcab34 /lib/sqfs
parentf85394c5887350a9728e108e72d908e08fc4cb78 (diff)
Cleanup: add SQFS_*/sqfs_* prefix to block processor
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs')
-rw-r--r--lib/sqfs/block_processor.c29
-rw-r--r--lib/sqfs/block_processor_parallel.c63
-rw-r--r--lib/sqfs/process_block.c10
3 files changed, 54 insertions, 48 deletions
diff --git a/lib/sqfs/block_processor.c b/lib/sqfs/block_processor.c
index 3a6926c..2bf307f 100644
--- a/lib/sqfs/block_processor.c
+++ b/lib/sqfs/block_processor.c
@@ -13,25 +13,27 @@
#include <stdlib.h>
#include <stdio.h>
-struct block_processor_t {
+struct sqfs_block_processor_t {
size_t max_block_size;
compressor_t *cmp;
- block_cb cb;
+ sqfs_block_cb cb;
void *user;
int status;
uint8_t scratch[];
};
-block_processor_t *block_processor_create(size_t max_block_size,
- compressor_t *cmp,
- unsigned int num_workers,
- void *user,
- block_cb callback)
+sqfs_block_processor_t *sqfs_block_processor_create(size_t max_block_size,
+ compressor_t *cmp,
+ unsigned int num_workers,
+ void *user,
+ sqfs_block_cb callback)
{
- block_processor_t *proc = alloc_flex(sizeof(*proc), 1, max_block_size);
+ sqfs_block_processor_t *proc;
(void)num_workers;
+ proc = alloc_flex(sizeof(*proc), 1, max_block_size);
+
if (proc == NULL) {
perror("Creating block processor");
return NULL;
@@ -44,15 +46,16 @@ block_processor_t *block_processor_create(size_t max_block_size,
return proc;
}
-void block_processor_destroy(block_processor_t *proc)
+void sqfs_block_processor_destroy(sqfs_block_processor_t *proc)
{
free(proc);
}
-int block_processor_enqueue(block_processor_t *proc, block_t *block)
+int sqfs_block_processor_enqueue(sqfs_block_processor_t *proc,
+ sqfs_block_t *block)
{
- if (process_block(block, proc->cmp,
- proc->scratch, proc->max_block_size))
+ if (sqfs_block_process(block, proc->cmp,
+ proc->scratch, proc->max_block_size))
goto fail;
if (proc->cb(proc->user, block))
@@ -66,7 +69,7 @@ fail:
return -1;
}
-int block_processor_finish(block_processor_t *proc)
+int sqfs_block_processor_finish(sqfs_block_processor_t *proc)
{
return proc->status;
}
diff --git a/lib/sqfs/block_processor_parallel.c b/lib/sqfs/block_processor_parallel.c
index a4e0f6e..6fca018 100644
--- a/lib/sqfs/block_processor_parallel.c
+++ b/lib/sqfs/block_processor_parallel.c
@@ -17,22 +17,22 @@
#define MAX_BACKLOG_FACTOR (10)
typedef struct {
- block_processor_t *shared;
+ sqfs_block_processor_t *shared;
compressor_t *cmp;
pthread_t thread;
uint8_t scratch[];
} compress_worker_t;
-struct block_processor_t {
+struct sqfs_block_processor_t {
pthread_mutex_t mtx;
pthread_cond_t queue_cond;
pthread_cond_t done_cond;
/* needs rw access by worker and main thread */
- block_t *queue;
- block_t *queue_last;
+ sqfs_block_t *queue;
+ sqfs_block_t *queue_last;
- block_t *done;
+ sqfs_block_t *done;
bool terminate;
size_t backlog;
@@ -41,7 +41,7 @@ struct block_processor_t {
uint32_t dequeue_id;
unsigned int num_workers;
- block_cb cb;
+ sqfs_block_cb cb;
void *user;
int status;
@@ -51,9 +51,10 @@ struct block_processor_t {
compress_worker_t *workers[];
};
-static void store_completed_block(block_processor_t *shared, block_t *blk)
+static void store_completed_block(sqfs_block_processor_t *shared,
+ sqfs_block_t *blk)
{
- block_t *it = shared->done, *prev = NULL;
+ sqfs_block_t *it = shared->done, *prev = NULL;
while (it != NULL) {
if (it->sequence_number >= blk->sequence_number)
@@ -74,8 +75,8 @@ static void store_completed_block(block_processor_t *shared, block_t *blk)
static void *worker_proc(void *arg)
{
compress_worker_t *worker = arg;
- block_processor_t *shared = worker->shared;
- block_t *blk = NULL;
+ sqfs_block_processor_t *shared = worker->shared;
+ sqfs_block_t *blk = NULL;
for (;;) {
pthread_mutex_lock(&shared->mtx);
@@ -103,21 +104,21 @@ static void *worker_proc(void *arg)
shared->queue_last = NULL;
pthread_mutex_unlock(&shared->mtx);
- if (process_block(blk, worker->cmp, worker->scratch,
- shared->max_block_size)) {
- blk->flags |= BLK_COMPRESS_ERROR;
+ if (sqfs_block_process(blk, worker->cmp, worker->scratch,
+ shared->max_block_size)) {
+ blk->flags |= SQFS_BLK_COMPRESS_ERROR;
}
}
return NULL;
}
-block_processor_t *block_processor_create(size_t max_block_size,
- compressor_t *cmp,
- unsigned int num_workers,
- void *user,
- block_cb callback)
+sqfs_block_processor_t *sqfs_block_processor_create(size_t max_block_size,
+ compressor_t *cmp,
+ unsigned int num_workers,
+ void *user,
+ sqfs_block_cb callback)
{
- block_processor_t *proc;
+ sqfs_block_processor_t *proc;
unsigned int i;
int ret;
@@ -210,10 +211,10 @@ fail_free:
return NULL;
}
-void block_processor_destroy(block_processor_t *proc)
+void sqfs_block_processor_destroy(sqfs_block_processor_t *proc)
{
+ sqfs_block_t *blk;
unsigned int i;
- block_t *blk;
pthread_mutex_lock(&proc->mtx);
proc->terminate = true;
@@ -246,15 +247,16 @@ void block_processor_destroy(block_processor_t *proc)
free(proc);
}
-static int process_completed_blocks(block_processor_t *proc, block_t *queue)
+static int process_completed_blocks(sqfs_block_processor_t *proc,
+ sqfs_block_t *queue)
{
- block_t *it;
+ sqfs_block_t *it;
while (queue != NULL) {
it = queue;
queue = queue->next;
- if (it->flags & BLK_COMPRESS_ERROR) {
+ if (it->flags & SQFS_BLK_COMPRESS_ERROR) {
proc->status = -1;
} else {
if (proc->cb(proc->user, it))
@@ -267,16 +269,17 @@ static int process_completed_blocks(block_processor_t *proc, block_t *queue)
return proc->status;
}
-int block_processor_enqueue(block_processor_t *proc, block_t *block)
+int sqfs_block_processor_enqueue(sqfs_block_processor_t *proc,
+ sqfs_block_t *block)
{
- block_t *queue = NULL, *it, *prev;
+ sqfs_block_t *queue = NULL, *it, *prev;
block->sequence_number = proc->enqueue_id++;
block->next = NULL;
pthread_mutex_lock(&proc->mtx);
- if ((block->flags & BLK_DONT_COMPRESS) &&
- (block->flags & BLK_DONT_CHECKSUM)) {
+ if ((block->flags & SQFS_BLK_DONT_COMPRESS) &&
+ (block->flags & SQFS_BLK_DONT_CHECKSUM)) {
store_completed_block(proc, block);
} else {
while (proc->backlog > proc->num_workers * MAX_BACKLOG_FACTOR)
@@ -313,9 +316,9 @@ int block_processor_enqueue(block_processor_t *proc, block_t *block)
return process_completed_blocks(proc, queue);
}
-int block_processor_finish(block_processor_t *proc)
+int sqfs_block_processor_finish(sqfs_block_processor_t *proc)
{
- block_t *queue, *it;
+ sqfs_block_t *queue, *it;
pthread_mutex_lock(&proc->mtx);
while (proc->backlog > 0)
diff --git a/lib/sqfs/process_block.c b/lib/sqfs/process_block.c
index a20b56b..b0c8a91 100644
--- a/lib/sqfs/process_block.c
+++ b/lib/sqfs/process_block.c
@@ -12,15 +12,15 @@
#include <string.h>
#include <zlib.h>
-int process_block(block_t *block, compressor_t *cmp,
- uint8_t *scratch, size_t scratch_size)
+int sqfs_block_process(sqfs_block_t *block, compressor_t *cmp,
+ uint8_t *scratch, size_t scratch_size)
{
ssize_t ret;
- if (!(block->flags & BLK_DONT_CHECKSUM))
+ if (!(block->flags & SQFS_BLK_DONT_CHECKSUM))
block->checksum = crc32(0, block->data, block->size);
- if (!(block->flags & BLK_DONT_COMPRESS)) {
+ if (!(block->flags & SQFS_BLK_DONT_COMPRESS)) {
ret = cmp->do_block(cmp, block->data, block->size,
scratch, scratch_size);
@@ -30,7 +30,7 @@ int process_block(block_t *block, compressor_t *cmp,
if (ret > 0) {
memcpy(block->data, scratch, ret);
block->size = ret;
- block->flags |= BLK_IS_COMPRESSED;
+ block->flags |= SQFS_BLK_IS_COMPRESSED;
}
}