- ret = main_writer_thread_init_ctx(ctx);
- if (ret)
- goto out_destroy_ctx;
-
- stream_list = ctx->stream_list;
- while (!list_empty(stream_list)) {
- lte = container_of(stream_list->next,
- struct wim_lookup_table_entry,
- write_streams_list);
- list_del(<e->write_streams_list);
- if (lte->unhashed && !lte->unique_size) {
- struct wim_lookup_table_entry *tmp;
- u32 orig_refcnt = lte->out_refcnt;
-
- ret = hash_unhashed_stream(lte, ctx->lookup_table, &tmp);
- if (ret)
- goto out_destroy_ctx;
- if (tmp != lte) {
- lte = tmp;
- if (orig_refcnt != tmp->out_refcnt) {
- DEBUG("Discarding duplicate stream of length %"PRIu64,
- wim_resource_size(lte));
- goto skip_to_progress;
- }
- }
- }
-
- if (wim_resource_size(lte) < 1000 ||
- ctx->out_ctype == WIMLIB_COMPRESSION_TYPE_NONE ||
- (lte->resource_location == RESOURCE_IN_WIM &&
- wimlib_get_compression_type(lte->wim) == ctx->out_ctype))
- {
- list_add(<e->write_streams_list,
- &ctx->serial_streams);
- } else {
- ret = submit_stream_for_compression(lte, ctx);
- if (ret)
- goto out_destroy_ctx;
- if (lte->unhashed) {
- list_del(<e->unhashed_list);
- lookup_table_insert(ctx->lookup_table, lte);
- lte->unhashed = 0;
- }
- }
- skip_to_progress:
- do_write_streams_progress(ctx->progress,
- ctx->progress_func,
- wim_resource_size(lte));
- }
-
- while (!list_empty(&ctx->outstanding_streams)) {
- ret = receive_compressed_chunks(ctx);
- if (ret)
- goto out_destroy_ctx;
+ if (wim_resource_size(lte) < 1000 ||
+ ctx->out_ctype == WIMLIB_COMPRESSION_TYPE_NONE ||
+ (lte->resource_location == RESOURCE_IN_WIM &&
+ !(ctx->write_resource_flags & WIMLIB_RESOURCE_FLAG_RECOMPRESS) &&
+ wimlib_get_compression_type(lte->wim) == ctx->out_ctype))
+ {
+ /* Stream is too small or isn't being compressed. Process it by
+ * the main thread when we have a chance. We can't necessarily
+ * process it right here, as the main thread could be in the
+ * middle of writing a different stream. */
+ list_add_tail(<e->write_streams_list, &ctx->serial_streams);
+ lte->deferred = 1;
+ ret = 0;
+ } else {
+ ret = submit_stream_for_compression(lte, ctx);