XZ Utils  5.2.8
Macros | Functions
outqueue.c File Reference

Output queue handling in multithreaded coding. More...

#include "outqueue.h"

Macros

#define BUF_SIZE_MAX   (UINT64_MAX / LZMA_THREADS_MAX / 2 / 2)
 

Functions

static lzma_ret get_options (uint64_t *bufs_alloc_size, uint32_t *bufs_count, uint64_t buf_size_max, uint32_t threads)
 
uint64_t lzma_outq_memusage (uint64_t buf_size_max, uint32_t threads)
 Calculate the memory usage of an output queue. More...
 
lzma_ret lzma_outq_init (lzma_outq *outq, const lzma_allocator *allocator, uint64_t buf_size_max, uint32_t threads)
 Initialize an output queue. More...
 
void lzma_outq_end (lzma_outq *outq, const lzma_allocator *allocator)
 Free the memory associated with the output queue. More...
 
lzma_outbuflzma_outq_get_buf (lzma_outq *outq)
 Get a new buffer. More...
 
bool lzma_outq_is_readable (const lzma_outq *outq)
 Test if there is data ready to be read. More...
 
lzma_ret lzma_outq_read (lzma_outq *restrict outq, uint8_t *restrict out, size_t *restrict out_pos, size_t out_size, lzma_vli *restrict unpadded_size, lzma_vli *restrict uncompressed_size)
 Read finished data. More...
 

Detailed Description

Output queue handling in multithreaded coding.

Macro Definition Documentation

◆ BUF_SIZE_MAX

#define BUF_SIZE_MAX   (UINT64_MAX / LZMA_THREADS_MAX / 2 / 2)

This is to ease integer overflow checking: We may allocate up to 2 * LZMA_THREADS_MAX buffers and we need some extra memory for other data structures (that's the second /2).

Function Documentation

◆ lzma_outq_memusage()

uint64_t lzma_outq_memusage ( uint64_t  buf_size_max,
uint32_t  threads 
)

Calculate the memory usage of an output queue.

Returns
Approximate memory usage in bytes or UINT64_MAX on error.

References get_options(), and LZMA_OK.

◆ lzma_outq_init()

lzma_ret lzma_outq_init ( lzma_outq outq,
const lzma_allocator allocator,
uint64_t  buf_size_max,
uint32_t  threads 
)

Initialize an output queue.

Parameters
outqPointer to an output queue. Before calling this function the first time, *outq should have been zeroed with memzero() so that this function knows that there are no previous allocations to free.
allocatorPointer to allocator or NULL
buf_size_maxMaximum amount of data that a single buffer in the queue may need to store.
threadsNumber of buffers that may be in use concurrently. Note that more than this number of buffers will actually get allocated to improve performance when buffers finish out of order.
Returns
- LZMA_OK
  • LZMA_MEM_ERROR

◆ lzma_outq_end()

void lzma_outq_end ( lzma_outq outq,
const lzma_allocator allocator 
)

Free the memory associated with the output queue.

◆ lzma_outq_get_buf()

lzma_outbuf* lzma_outq_get_buf ( lzma_outq outq)

Get a new buffer.

lzma_outq_has_buf() must be used to check that there is a buffer available before calling lzma_outq_get_buf().

◆ lzma_outq_is_readable()

bool lzma_outq_is_readable ( const lzma_outq outq)

Test if there is data ready to be read.

Call to this function must be protected with the same mutex that is used to protect lzma_outbuf.finished.

References lzma_outq::bufs, lzma_outq::bufs_allocated, lzma_outq::bufs_pos, lzma_outq::bufs_used, and lzma_outbuf::finished.

Referenced by wait_for_work().

◆ lzma_outq_read()

lzma_ret lzma_outq_read ( lzma_outq *restrict  outq,
uint8_t *restrict  out,
size_t *restrict  out_pos,
size_t  out_size,
lzma_vli *restrict  unpadded_size,
lzma_vli *restrict  uncompressed_size 
)

Read finished data.

Parameters
outqPointer to an output queue
outBeginning of the output buffer
out_posThe next byte will be written to out[*out_pos].
out_sizeSize of the out buffer; the first byte into which no data is written to is out[out_size].
unpadded_sizeUnpadded Size from the Block encoder
uncompressed_sizeUncompressed Size from the Block encoder
Returns
- LZMA: All OK. Either no data was available or the buffer being read didn't become empty yet.
  • LZMA_STREAM_END: The buffer being read was finished. *unpadded_size and *uncompressed_size were set.
Note
This reads lzma_outbuf.finished variables and thus call to this function needs to be protected with a mutex.