aboutsummaryrefslogtreecommitdiff
path: root/lib/sqfs
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-12-05 15:44:50 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-12-05 15:44:50 +0100
commit9ea91c044106537453ae6e13368b60ce532c885c (patch)
tree0a597427a9f22b7b77a76314ca10791bef00a262 /lib/sqfs
parente17da4c1150b1f8be9071c7403163ea6fb518c6e (diff)
Minor data writer cleanup
Move "do block" function over to the rest of the block related code and internalizie the pthread worker structure. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs')
-rw-r--r--lib/sqfs/data_writer/block.c31
-rw-r--r--lib/sqfs/data_writer/common.c31
-rw-r--r--lib/sqfs/data_writer/internal.h10
-rw-r--r--lib/sqfs/data_writer/pthread.c7
4 files changed, 39 insertions, 40 deletions
diff --git a/lib/sqfs/data_writer/block.c b/lib/sqfs/data_writer/block.c
index 13c62a2..9396e4a 100644
--- a/lib/sqfs/data_writer/block.c
+++ b/lib/sqfs/data_writer/block.c
@@ -170,3 +170,34 @@ int process_completed_block(sqfs_data_writer_t *proc, sqfs_block_t *blk)
return 0;
}
+
+int data_writer_do_block(sqfs_block_t *block, sqfs_compressor_t *cmp,
+ sqfs_u8 *scratch, size_t scratch_size)
+{
+ ssize_t ret;
+
+ if (block->size == 0) {
+ block->checksum = 0;
+ return 0;
+ }
+
+ block->checksum = crc32(0, block->data, block->size);
+
+ if (block->flags & SQFS_BLK_IS_FRAGMENT)
+ return 0;
+
+ if (!(block->flags & SQFS_BLK_DONT_COMPRESS)) {
+ ret = cmp->do_block(cmp, block->data, block->size,
+ scratch, scratch_size);
+ if (ret < 0)
+ return ret;
+
+ if (ret > 0) {
+ memcpy(block->data, scratch, ret);
+ block->size = ret;
+ block->flags |= SQFS_BLK_IS_COMPRESSED;
+ }
+ }
+
+ return 0;
+}
diff --git a/lib/sqfs/data_writer/common.c b/lib/sqfs/data_writer/common.c
index a19eb6d..5fe70ac 100644
--- a/lib/sqfs/data_writer/common.c
+++ b/lib/sqfs/data_writer/common.c
@@ -98,37 +98,6 @@ sqfs_block_t *data_writer_next_work_item(sqfs_data_writer_t *proc)
return blk;
}
-int data_writer_do_block(sqfs_block_t *block, sqfs_compressor_t *cmp,
- sqfs_u8 *scratch, size_t scratch_size)
-{
- ssize_t ret;
-
- if (block->size == 0) {
- block->checksum = 0;
- return 0;
- }
-
- block->checksum = crc32(0, block->data, block->size);
-
- if (block->flags & SQFS_BLK_IS_FRAGMENT)
- return 0;
-
- if (!(block->flags & SQFS_BLK_DONT_COMPRESS)) {
- ret = cmp->do_block(cmp, block->data, block->size,
- scratch, scratch_size);
- if (ret < 0)
- return ret;
-
- if (ret > 0) {
- memcpy(block->data, scratch, ret);
- block->size = ret;
- block->flags |= SQFS_BLK_IS_COMPRESSED;
- }
- }
-
- return 0;
-}
-
int sqfs_data_writer_write_fragment_table(sqfs_data_writer_t *proc,
sqfs_super_t *super)
{
diff --git a/lib/sqfs/data_writer/internal.h b/lib/sqfs/data_writer/internal.h
index 7af6ab4..fab6c50 100644
--- a/lib/sqfs/data_writer/internal.h
+++ b/lib/sqfs/data_writer/internal.h
@@ -45,15 +45,7 @@ typedef struct {
sqfs_u64 hash;
} frag_info_t;
-
-#ifdef WITH_PTHREAD
-typedef struct {
- sqfs_data_writer_t *shared;
- sqfs_compressor_t *cmp;
- pthread_t thread;
- sqfs_u8 scratch[];
-} compress_worker_t;
-#endif
+typedef struct compress_worker_t compress_worker_t;
struct sqfs_data_writer_t {
/* synchronization primitives */
diff --git a/lib/sqfs/data_writer/pthread.c b/lib/sqfs/data_writer/pthread.c
index 915ea2a..1830d07 100644
--- a/lib/sqfs/data_writer/pthread.c
+++ b/lib/sqfs/data_writer/pthread.c
@@ -7,6 +7,13 @@
#define SQFS_BUILDING_DLL
#include "internal.h"
+struct compress_worker_t {
+ sqfs_data_writer_t *shared;
+ sqfs_compressor_t *cmp;
+ pthread_t thread;
+ sqfs_u8 scratch[];
+};
+
static void *worker_proc(void *arg)
{
compress_worker_t *worker = arg;