Rizin
unix-like reverse engineering framework and cli tools
|
Multithreaded .xz Stream encoder. More...
#include "filter_encoder.h"
#include "easy_preset.h"
#include "block_encoder.h"
#include "block_buffer_encoder.h"
#include "index_encoder.h"
#include "outqueue.h"
Go to the source code of this file.
Classes | |
struct | worker_thread_s |
struct | lzma_stream_coder_s |
Macros | |
#define | BLOCK_SIZE_MAX (UINT64_MAX / LZMA_THREADS_MAX) |
Typedefs | |
typedef struct lzma_stream_coder_s | lzma_stream_coder |
typedef struct worker_thread_s | worker_thread |
Enumerations | |
enum | worker_state { THR_IDLE , THR_RUN , THR_FINISH , THR_STOP , THR_EXIT } |
Multithreaded .xz Stream encoder.
Definition in file stream_encoder_mt.c.
#define BLOCK_SIZE_MAX (UINT64_MAX / LZMA_THREADS_MAX) |
Maximum supported block size. This makes it simpler to prevent integer overflows if we are given unusually large block size.
Definition at line 23 of file stream_encoder_mt.c.
typedef struct lzma_stream_coder_s lzma_stream_coder |
Definition at line 1 of file stream_encoder_mt.c.
typedef struct worker_thread_s worker_thread |
Definition at line 1 of file stream_encoder_mt.c.
enum worker_state |
Definition at line 26 of file stream_encoder_mt.c.
|
static |
Options handling for lzma_stream_encoder_mt_init() and lzma_stream_encoder_mt_memusage()
Definition at line 866 of file stream_encoder_mt.c.
References assert(), BLOCK_SIZE_MAX, filters, lzma_options_easy::filters, lzma_block_buffer_bound64(), lzma_easy_preset(), LZMA_MEM_ERROR, lzma_mt_block_size(), LZMA_OK, LZMA_OPTIONS_ERROR, LZMA_PROG_ERROR, LZMA_THREADS_MAX, NULL, and options.
Referenced by LZMA_API(), and stream_encoder_mt_init().
|
static |
Definition at line 916 of file stream_encoder_mt.c.
References i, and progress_in.
Referenced by stream_encoder_mt_init().
|
static |
Definition at line 515 of file stream_encoder_mt.c.
References allocator, initialize_new_thread(), LZMA_OK, lzma_outq_get_buf(), lzma_outq_has_buf(), NULL, return_if_error, and THR_RUN.
Referenced by stream_encode_in().
|
static |
Initialize a new worker_thread structure and create a new thread.
Definition at line 472 of file stream_encoder_mt.c.
References allocator, worker_thread_s::allocator, worker_thread_s::block_encoder, worker_thread_s::coder, worker_thread_s::cond, worker_thread_s::in, lzma_alloc(), lzma_free(), LZMA_MEM_ERROR, LZMA_NEXT_CODER_INIT, LZMA_OK, worker_thread_s::mutex, NULL, worker_thread_s::progress_in, worker_thread_s::progress_out, worker_thread_s::state, THR_IDLE, worker_thread_s::thread_id, and worker_start().
Referenced by get_thread().
LZMA_API | ( | lzma_ret | ) |
Definition at line 1078 of file stream_encoder_mt.c.
References lzma_stream::internal, LZMA_FINISH, LZMA_FULL_BARRIER, LZMA_FULL_FLUSH, lzma_next_strm_init, LZMA_OK, LZMA_RUN, options, stream_encoder_mt_init(), strm, and lzma_internal_s::supported_actions.
LZMA_API | ( | uint64_t | ) |
Calculate approximate memory usage of easy encoder.
Get the total amount of physical memory (RAM) in bytes.
Calculate approximate memory usage of multithreaded .xz encoder.
Calculate approximate decoder memory usage of a preset.
This function is a wrapper for lzma_raw_encoder_memusage().
preset | Compression preset (level and possible flags) |
This function is a wrapper for lzma_raw_decoder_memusage().
preset | Compression preset (level and possible flags) |
Since doing the encoding in threaded mode doesn't affect the memory requirements of single-threaded decompressor, you can use lzma_easy_decoder_memusage(options->preset) or lzma_raw_decoder_memusage(options->filters) to calculate the decompressor memory requirements.
options | Compression options |
Calculate approximate memory usage of easy encoder.
Get the uncompressed size of the file.
Get the total size of the file.
Get the total size of the Blocks.
Get the total size of the Stream.
Get the size of the Index field as bytes.
Get the number of Blocks.
Get the number of Streams.
Calculate the memory usage of an existing lzma_index.
On disk, the size of the Index field depends on both the number of Records stored and how big values the Records store (due to variable-length integer encoding). When the Index is kept in lzma_index structure, the memory usage depends only on the number of Records/Blocks stored in the Index(es), and in case of concatenated lzma_indexes, the number of Streams. The size in RAM is almost always significantly bigger than in the encoded form on disk.
This function calculates an approximate amount of memory needed hold the given number of Streams and Blocks in lzma_index structure. This value may vary between CPU architectures and also between liblzma versions if the internal implementation is modified.
This is a shorthand for lzma_index_memusage(lzma_index_stream_count(i), lzma_index_block_count(i)).
This returns the total number of Blocks in lzma_index. To get number of Blocks in individual Streams, use lzma_index_iter.
This is needed to verify the Backward Size field in the Stream Footer.
If multiple lzma_indexes have been combined, this works as if the Blocks were in a single Stream. This is useful if you are going to combine Blocks from multiple Streams into a single new Stream.
This doesn't include the Stream Header, Stream Footer, Stream Padding, or Index fields.
When no lzma_indexes have been combined with lzma_index_cat() and there is no Stream Padding, this function is identical to lzma_index_stream_size(). If multiple lzma_indexes have been combined, this includes also the headers of each separate Stream and the possible Stream Padding fields.
Definition at line 1096 of file stream_encoder_mt.c.
References A, A1, aligned_read32ne(), B, bswap64, C, D, filters, get_options(), limit, lzma_crc64_table, LZMA_MEMUSAGE_BASE, LZMA_OK, lzma_outq_memusage(), options, S32, S8, autogen_x86imm::tmp, and UINT64_MAX.
|
static |
Definition at line 553 of file stream_encoder_mt.c.
References test-lz4-speed::action, allocator, finish(), get_thread(), in, in_pos, in_size, lzma_bufcpy(), LZMA_OK, LZMA_RUN, NULL, THR_FINISH, and THR_IDLE.
Referenced by stream_encode_mt().
|
static |
Definition at line 667 of file stream_encoder_mt.c.
References test-lz4-speed::action, allocator, assert(), lzma_stream_flags::backward_size, lzma_next_coder_s::code, lzma_next_coder_s::coder, in, in_pos, in_size, lzma_stream_coder::index, lzma_stream_coder::index_encoder, lzma_bufcpy(), LZMA_FINISH, LZMA_FULL_BARRIER, LZMA_FULL_FLUSH, lzma_index_encoder_init(), LZMA_OK, lzma_outq_is_empty(), lzma_outq_read(), LZMA_PROG_ERROR, LZMA_RUN, LZMA_STREAM_END, LZMA_STREAM_HEADER_SIZE, LZMA_TIMED_OUT, NULL, out, out_pos, return_if_error, lzma_stream_coder::sequence, stream_encode_in(), lzma_stream_coder::stream_flags, threads_stop(), uncompressed_size, unpadded_size, and wait_for_work().
Referenced by stream_encoder_mt_init().
|
static |
Definition at line 841 of file stream_encoder_mt.c.
References allocator, lzma_stream_coder::filters, i, lzma_filter::id, lzma_stream_coder::index, lzma_stream_coder::index_encoder, lzma_free(), lzma_next_end(), lzma_outq_end(), LZMA_VLI_UNKNOWN, lzma_filter::options, and threads_end().
Referenced by stream_encoder_mt_init().
|
static |
Definition at line 940 of file stream_encoder_mt.c.
References allocator, assert(), lzma_stream_flags::check, lzma_next_coder_s::code, lzma_next_coder_s::coder, lzma_next_coder_s::end, filters, lzma_stream_coder::filters, get_options(), get_progress(), lzma_next_coder_s::get_progress, i, lzma_filter::id, lzma_stream_coder::index, lzma_stream_coder::index_encoder, lzma_alloc(), LZMA_CHECK_ID_MAX, lzma_free(), LZMA_MEM_ERROR, LZMA_NEXT_CODER_INIT, lzma_next_coder_init, LZMA_OK, LZMA_OPTIONS_ERROR, lzma_outq_init(), LZMA_PROG_ERROR, LZMA_STREAM_HEADER_SIZE, LZMA_UNSUPPORTED_CHECK, LZMA_VLI_UNKNOWN, memzero, NULL, options, lzma_filter::options, return_if_error, lzma_stream_coder::sequence, SIZE_MAX, stream_encode_mt(), stream_encoder_mt_end(), lzma_stream_coder::stream_flags, threads_end(), threads_stop(), UINT64_MAX, and lzma_stream_flags::version.
Referenced by LZMA_API().
|
static |
Stop the threads and free the resources associated with them. Wait until the threads have exited.
Definition at line 450 of file stream_encoder_mt.c.
References allocator, assert(), i, lzma_free(), and THR_EXIT.
Referenced by stream_encoder_mt_end(), and stream_encoder_mt_init().
|
static |
Make the threads stop but not exit. Optionally wait for them to stop.
Definition at line 421 of file stream_encoder_mt.c.
References i, THR_IDLE, and THR_STOP.
Referenced by stream_encode_mt(), and stream_encoder_mt_init().
|
static |
Wait until more input can be consumed, more output can be read, or an optional timeout is reached.
Definition at line 621 of file stream_encoder_mt.c.
References LZMA_OK, lzma_outq_has_buf(), lzma_outq_is_readable(), and NULL.
Referenced by stream_encode_mt().
|
static |
Definition at line 199 of file stream_encoder_mt.c.
References test-lz4-speed::action, worker_thread_s::allocator, assert(), worker_thread_s::block_encoder, worker_thread_s::block_options, lzma_outbuf::buf, lzma_stream_flags::check, lzma_next_coder_s::code, lzma_next_coder_s::coder, worker_thread_s::coder, worker_thread_s::cond, lzma_stream_coder::filters, lzma_block::header_size, worker_thread_s::in, in_pos, in_size, worker_thread_s::in_size, lzma_block_encoder_init(), LZMA_FINISH, LZMA_OK, LZMA_PROG_ERROR, LZMA_RUN, LZMA_STREAM_END, worker_thread_s::mutex, worker_thread_s::outbuf, worker_thread_s::progress_in, worker_thread_s::progress_out, lzma_outbuf::size, worker_thread_s::state, lzma_stream_coder::stream_flags, THR_FINISH, THR_RUN, THR_STOP, lzma_block::uncompressed_size, lzma_outbuf::uncompressed_size, lzma_outbuf::unpadded_size, lzma_block::version, and worker_error().
Referenced by worker_start().
|
static |
Tell the main thread that something has gone wrong.
Definition at line 182 of file stream_encoder_mt.c.
References assert(), worker_thread_s::coder, LZMA_OK, and LZMA_STREAM_END.
Referenced by worker_encode().
|
static |
Definition at line 346 of file stream_encoder_mt.c.
References worker_thread_s::allocator, assert(), worker_thread_s::block_encoder, worker_thread_s::coder, worker_thread_s::cond, lzma_outbuf::finished, worker_thread_s::in, lzma_free(), lzma_next_end(), worker_thread_s::mutex, worker_thread_s::next, worker_thread_s::outbuf, worker_thread_s::progress_in, worker_thread_s::progress_out, lzma_outbuf::size, worker_thread_s::state, THR_EXIT, THR_FINISH, THR_IDLE, THR_STOP, lzma_outbuf::uncompressed_size, and worker_encode().
Referenced by initialize_new_thread().