XZ Utils  5.4.1
Data Structures | Enumerations | Functions
stream_decoder_mt.c File Reference

Multithreaded .xz Stream decoder. More...

#include "common.h"
#include "block_decoder.h"
#include "stream_decoder.h"
#include "index.h"
#include "outqueue.h"

Data Structures

struct  worker_thread
 
struct  lzma_stream_coder
 

Enumerations

enum  worker_state {
  THR_IDLE, THR_RUN, THR_STOP, THR_EXIT,
  THR_IDLE, THR_RUN, THR_FINISH, THR_STOP,
  THR_EXIT
}
 
enum  partial_update_mode { PARTIAL_DISABLED, PARTIAL_START, PARTIAL_ENABLED }
 

Functions

static void worker_enable_partial_update (void *thr_ptr)
 
static void worker_stop (struct worker_thread *thr)
 
static MYTHREAD_RET_TYPE worker_decoder (void *thr_ptr)
 
static void threads_end (struct lzma_stream_coder *coder, const lzma_allocator *allocator)
 Tells the worker threads to exit and waits for them to terminate. More...
 
static void threads_stop (struct lzma_stream_coder *coder)
 
static lzma_ret initialize_new_thread (struct lzma_stream_coder *coder, const lzma_allocator *allocator)
 Initialize a new worker_thread structure and create a new thread. More...
 
static lzma_ret get_thread (struct lzma_stream_coder *coder, const lzma_allocator *allocator)
 
static lzma_ret read_output_and_wait (struct lzma_stream_coder *coder, const lzma_allocator *allocator, uint8_t *restrict out, size_t *restrict out_pos, size_t out_size, bool *input_is_possible, bool waiting_allowed, mythread_condtime *wait_abs, bool *has_blocked)
 
static lzma_ret decode_block_header (struct lzma_stream_coder *coder, const lzma_allocator *allocator, const uint8_t *restrict in, size_t *restrict in_pos, size_t in_size)
 
static size_t comp_blk_size (const struct lzma_stream_coder *coder)
 Get the size of the Compressed Data + Block Padding + Check. More...
 
static bool is_direct_mode_needed (lzma_vli size)
 
static lzma_ret stream_decoder_reset (struct lzma_stream_coder *coder, const lzma_allocator *allocator)
 
static lzma_ret stream_decode_mt (void *coder_ptr, const lzma_allocator *allocator, const uint8_t *restrict in, size_t *restrict in_pos, size_t in_size, uint8_t *restrict out, size_t *restrict out_pos, size_t out_size, lzma_action action)
 
static void stream_decoder_mt_end (void *coder_ptr, const lzma_allocator *allocator)
 
static lzma_check stream_decoder_mt_get_check (const void *coder_ptr)
 
static lzma_ret stream_decoder_mt_memconfig (void *coder_ptr, uint64_t *memusage, uint64_t *old_memlimit, uint64_t new_memlimit)
 
static void stream_decoder_mt_get_progress (void *coder_ptr, uint64_t *progress_in, uint64_t *progress_out)
 
static lzma_ret stream_decoder_mt_init (lzma_next_coder *next, const lzma_allocator *allocator, const lzma_mt *options)
 
lzma_ret lzma_stream_decoder_mt (lzma_stream *strm, const lzma_mt *options)
 Initialize multithreaded .xz Stream decoder. More...
 

Detailed Description

Multithreaded .xz Stream decoder.

Enumeration Type Documentation

◆ worker_state

Enumerator
THR_IDLE 

Waiting for work. Main thread may change this to THR_RUN or THR_EXIT.

THR_RUN 

Decoding is in progress. Main thread may change this to THR_STOP or THR_EXIT. The worker thread may change this to THR_IDLE.

THR_STOP 

The main thread wants the thread to stop whatever it was doing but not exit. Main thread may change this to THR_EXIT. The worker thread may change this to THR_IDLE.

THR_EXIT 

The main thread wants the thread to exit.

THR_IDLE 

Waiting for work.

THR_RUN 

Encoding is in progress.

THR_FINISH 

Encoding is in progress but no more input data will be read.

THR_STOP 

The main thread wants the thread to stop whatever it was doing but not exit.

THR_EXIT 

The main thread wants the thread to exit. We could use cancellation but since there's stopped anyway, this is lazier.

◆ partial_update_mode

Enumerator
PARTIAL_DISABLED 

Partial updates (storing of worker thread progress to lzma_outbuf) are disabled.

PARTIAL_START 

Main thread requests partial updates to be enabled but no partial update has been done by the worker thread yet.

Changing from PARTIAL_DISABLED to PARTIAL_START requires use of the worker-thread mutex. Other transitions don't need a mutex.

PARTIAL_ENABLED 

Partial updates are enabled and the worker thread has done at least one partial update.

Function Documentation

◆ worker_enable_partial_update()

static void worker_enable_partial_update ( void *  thr_ptr)
static

Enables updating of outbuf->pos. This is a callback function that is used with lzma_outq_enable_partial_output().

References PARTIAL_START, and worker_thread::partial_update.

◆ worker_stop()

static void worker_stop ( struct worker_thread thr)
static

Things do to at THR_STOP or when finishing a Block. This is called with thr->mutex locked.

References worker_thread::coder, worker_thread::in_size, lzma_stream_coder::mem_cached, worker_thread::mem_filters, lzma_stream_coder::mem_in_use, worker_thread::next, and lzma_stream_coder::threads_free.

◆ threads_end()

static void threads_end ( struct lzma_stream_coder coder,
const lzma_allocator allocator 
)
static

◆ initialize_new_thread()

static lzma_ret initialize_new_thread ( struct lzma_stream_coder coder,
const lzma_allocator allocator 
)
static

Initialize a new worker_thread structure and create a new thread.

References lzma_alloc(), LZMA_MEM_ERROR, lzma_stream_coder::threads, and lzma_stream_coder::threads_max.

◆ comp_blk_size()

static size_t comp_blk_size ( const struct lzma_stream_coder coder)
static

◆ is_direct_mode_needed()

static bool is_direct_mode_needed ( lzma_vli  size)
static

Returns true if the size (compressed or uncompressed) is such that threaded decompression cannot be used. Sizes that are too big compared to SIZE_MAX must be rejected to avoid integer overflows and truncations when lzma_vli is assigned to a size_t.

References LZMA_VLI_UNKNOWN.

◆ lzma_stream_decoder_mt()

lzma_ret lzma_stream_decoder_mt ( lzma_stream strm,
const lzma_mt options 
)

Initialize multithreaded .xz Stream decoder.

Parameters
strmPointer to properly prepared lzma_stream
optionsPointer to multithreaded compression options

The decoder can decode multiple Blocks in parallel. This requires that each Block Header contains the Compressed Size and Uncompressed size fields which are added by the multi-threaded encoder, see lzma_stream_encoder_mt().

A Stream with one Block will only utilize one thread. A Stream with multiple Blocks but without size information in Block Headers will be processed in single-threaded mode in the same way as done by lzma_stream_decoder(). Concatenated Streams are processed one Stream at a time; no inter-Stream parallelization is done.

This function behaves like lzma_stream_decoder() when options->threads == 1 and options->memlimit_threading <= 1.

Returns
- LZMA_OK: Initialization was successful.
  • LZMA_MEM_ERROR: Cannot allocate memory.
  • LZMA_MEMLIMIT_ERROR: Memory usage limit was reached.
  • LZMA_OPTIONS_ERROR: Unsupported flags.
  • LZMA_PROG_ERROR

References lzma_next_strm_init.