XZ Utils 5.3.3alpha
|
Output queue handling in multithreaded coding. More...
#include "outqueue.h"
Macros | |
#define | GET_BUFS_LIMIT(threads) (2 * (threads)) |
Functions | |
uint64_t | lzma_outq_memusage (uint64_t buf_size_max, uint32_t threads) |
Calculate the memory usage of an output queue. More... | |
static void | move_head_to_cache (lzma_outq *outq, const lzma_allocator *allocator) |
static void | free_one_cached_buffer (lzma_outq *outq, const lzma_allocator *allocator) |
void | lzma_outq_clear_cache (lzma_outq *outq, const lzma_allocator *allocator) |
Free all cached buffers that consume memory but aren't in use. More... | |
void | lzma_outq_clear_cache2 (lzma_outq *outq, const lzma_allocator *allocator, size_t keep_size) |
Like lzma_outq_clear_cache() but might keep one buffer. More... | |
lzma_ret | lzma_outq_init (lzma_outq *outq, const lzma_allocator *allocator, 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_ret | lzma_outq_prealloc_buf (lzma_outq *outq, const lzma_allocator *allocator, size_t size) |
Preallocate a new buffer into cache. More... | |
lzma_outbuf * | lzma_outq_get_buf (lzma_outq *outq, void *worker) |
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, const lzma_allocator *restrict allocator, 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... | |
void | lzma_outq_enable_partial_output (lzma_outq *outq, void(*enable_partial_output)(void *worker)) |
Enable partial output from a worker thread. More... | |
Output queue handling in multithreaded coding.
#define GET_BUFS_LIMIT | ( | threads | ) | (2 * (threads)) |
Get the maximum number of buffers that may be allocated based on the number of threads. For now this is twice the number of threads. It's a compromise between RAM usage and keeping the worker threads busy when buffers finish out of order.
uint64_t lzma_outq_memusage | ( | uint64_t | buf_size_max, |
uint32_t | threads | ||
) |
Calculate the memory usage of an output queue.
void lzma_outq_clear_cache | ( | lzma_outq * | outq, |
const lzma_allocator * | allocator | ||
) |
Free all cached buffers that consume memory but aren't in use.
void lzma_outq_clear_cache2 | ( | lzma_outq * | outq, |
const lzma_allocator * | allocator, | ||
size_t | keep_size | ||
) |
Like lzma_outq_clear_cache() but might keep one buffer.
One buffer is not freed if its size is equal to keep_size. This is useful if the caller knows that it will soon need a buffer of keep_size bytes. This way it won't be freed and immediately reallocated.
lzma_ret lzma_outq_init | ( | lzma_outq * | outq, |
const lzma_allocator * | allocator, | ||
uint32_t | threads | ||
) |
Initialize an output queue.
outq | Pointer 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. |
allocator | Pointer to allocator or NULL |
threads | Number of buffers that may be in use concurrently. Note that more than this number of buffers may actually get allocated to improve performance when buffers finish out of order. The actual maximum number of allocated buffers is derived from the number of threads. |
void lzma_outq_end | ( | lzma_outq * | outq, |
const lzma_allocator * | allocator | ||
) |
Free the memory associated with the output queue.
lzma_ret lzma_outq_prealloc_buf | ( | lzma_outq * | outq, |
const lzma_allocator * | allocator, | ||
size_t | size | ||
) |
Preallocate a new buffer into cache.
Splitting the buffer allocation into a separate function makes it possible to ensure that way lzma_outq_get_buf() cannot fail. If the preallocated buffer isn't actually used (for example, some other error occurs), the caller has to do nothing as the buffer will be used later or cleared from the cache when not needed.
lzma_outbuf * lzma_outq_get_buf | ( | lzma_outq * | outq, |
void * | worker | ||
) |
Get a new buffer.
lzma_outq_prealloc_buf() must be used to ensure that there is a buffer available before calling lzma_outq_get_buf().
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_outbuf_s::finished, lzma_outq::head, lzma_outbuf_s::pos, and lzma_outq::read_pos.
Referenced by wait_for_work().
lzma_ret lzma_outq_read | ( | lzma_outq *restrict | outq, |
const lzma_allocator *restrict | allocator, | ||
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.
outq | Pointer to an output queue |
out | Beginning of the output buffer |
out_pos | The next byte will be written to out[*out_pos]. |
out_size | Size of the out buffer; the first byte into which no data is written to is out[out_size]. |
unpadded_size | Unpadded Size from the Block encoder |
uncompressed_size | Uncompressed Size from the Block encoder |
void lzma_outq_enable_partial_output | ( | lzma_outq * | outq, |
void(*)(void *worker) | enable_partial_output | ||
) |
Enable partial output from a worker thread.
If the buffer at the head of the output queue isn't finished, this will call enable_partial_output on the worker associated with that output buffer.
References lzma_outbuf_s::finished, lzma_outq::head, and lzma_outbuf_s::worker.