aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-01-24 11:56:20 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-01-24 16:15:47 +0100
commitf7c29ffee7fdd61470fd879cfae470534423c0c7 (patch)
tree81688531a5ec3729e3957c50d666e2d3cb264a77
parenta9763a118ddceaffb99eb7d89b6a2d1f56b1e9df (diff)
Cleanup: remove single use helper functions from data writer
This commit moves the single use helper functions that are called from worker thread context into the worker thread function. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--lib/sqfs/data_writer/common.c41
-rw-r--r--lib/sqfs/data_writer/internal.h7
-rw-r--r--lib/sqfs/data_writer/winpthread.c34
3 files changed, 31 insertions, 51 deletions
diff --git a/lib/sqfs/data_writer/common.c b/lib/sqfs/data_writer/common.c
index d316a6f..d2bf935 100644
--- a/lib/sqfs/data_writer/common.c
+++ b/lib/sqfs/data_writer/common.c
@@ -55,47 +55,6 @@ void data_writer_cleanup(sqfs_data_writer_t *proc)
free(proc);
}
-void data_writer_store_done(sqfs_data_writer_t *proc, sqfs_block_t *blk,
- int status)
-{
- sqfs_block_t *it = proc->done, *prev = NULL;
-
- while (it != NULL) {
- if (it->sequence_number >= blk->sequence_number)
- break;
- prev = it;
- it = it->next;
- }
-
- if (prev == NULL) {
- blk->next = proc->done;
- proc->done = blk;
- } else {
- blk->next = prev->next;
- prev->next = blk;
- }
-
- if (status != 0 && proc->status == 0)
- proc->status = status;
-}
-
-sqfs_block_t *data_writer_next_work_item(sqfs_data_writer_t *proc)
-{
- sqfs_block_t *blk;
-
- if (proc->status != 0)
- return NULL;
-
- blk = proc->queue;
- proc->queue = blk->next;
- blk->next = NULL;
-
- if (proc->queue == NULL)
- proc->queue_last = NULL;
-
- return blk;
-}
-
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 1a85644..8a3f4d7 100644
--- a/lib/sqfs/data_writer/internal.h
+++ b/lib/sqfs/data_writer/internal.h
@@ -134,13 +134,6 @@ int data_writer_init(sqfs_data_writer_t *proc, size_t max_block_size,
SQFS_INTERNAL void data_writer_cleanup(sqfs_data_writer_t *proc);
SQFS_INTERNAL
-void data_writer_store_done(sqfs_data_writer_t *proc, sqfs_block_t *blk,
- int status);
-
-SQFS_INTERNAL
-sqfs_block_t *data_writer_next_work_item(sqfs_data_writer_t *proc);
-
-SQFS_INTERNAL
int data_writer_do_block(sqfs_block_t *block, sqfs_compressor_t *cmp,
sqfs_u8 *scratch, size_t scratch_size);
diff --git a/lib/sqfs/data_writer/winpthread.c b/lib/sqfs/data_writer/winpthread.c
index bba5894..e575859 100644
--- a/lib/sqfs/data_writer/winpthread.c
+++ b/lib/sqfs/data_writer/winpthread.c
@@ -38,20 +38,48 @@ static THREAD_TYPE worker_proc(THREAD_ARG arg)
{
compress_worker_t *worker = arg;
sqfs_data_writer_t *shared = worker->shared;
- sqfs_block_t *blk = NULL;
+ sqfs_block_t *it, *prev, *blk = NULL;
int status = 0;
for (;;) {
LOCK(&shared->mtx);
if (blk != NULL) {
- data_writer_store_done(shared, blk, status);
+ it = shared->done;
+ prev = NULL;
+
+ while (it != NULL) {
+ if (it->sequence_number >= blk->sequence_number)
+ break;
+ prev = it;
+ it = it->next;
+ }
+
+ if (prev == NULL) {
+ blk->next = shared->done;
+ shared->done = blk;
+ } else {
+ blk->next = prev->next;
+ prev->next = blk;
+ }
+
+ if (status != 0 && shared->status == 0)
+ shared->status = status;
SIGNAL_ALL(&shared->done_cond);
}
while (shared->queue == NULL && shared->status == 0)
AWAIT(&shared->queue_cond, &shared->mtx);
- blk = data_writer_next_work_item(shared);
+ if (shared->status == 0) {
+ blk = shared->queue;
+ shared->queue = blk->next;
+ blk->next = NULL;
+
+ if (shared->queue == NULL)
+ shared->queue_last = NULL;
+ } else {
+ blk = NULL;
+ }
UNLOCK(&shared->mtx);
if (blk == NULL)