4 * Interface for serial/parallel chunk compression.
7 #ifndef _WIMLIB_CHUNK_COMPRESSOR_H
8 #define _WIMLIB_CHUNK_COMPRESSOR_H
10 #include "wimlib/types.h"
12 /* Interface for chunk compression. Users can submit chunks of data to be
13 * compressed, then retrieve them later in order. This interface can be
14 * implemented either in serial (having the calling thread compress the chunks
15 * itself) or in parallel (having other threads asynchronously compress the
17 struct chunk_compressor {
18 /* Variables set by the chunk compressor when it is created. */
23 /* Free the chunk compressor. */
24 void (*destroy)(struct chunk_compressor *);
26 /* Try to borrow a buffer into which the uncompressed data for the next
27 * chunk should be prepared.
29 * Only one buffer can be borrowed at a time.
31 * Returns a pointer to the buffer, or NULL if no buffer is available.
32 * If no buffer is available, you must call ->get_compression_result()
33 * to retrieve a compressed chunk before trying again. */
34 void *(*get_chunk_buffer)(struct chunk_compressor *);
36 /* Signals to the chunk compressor that the buffer which was loaned out
37 * from ->get_chunk_buffer() has finished being filled and contains the
38 * specified number of bytes of uncompressed data. */
39 void (*signal_chunk_filled)(struct chunk_compressor *, u32);
41 /* Get the next chunk of compressed data.
43 * The compressed data, along with its size and the size of the original
44 * uncompressed chunk, are returned in the locations pointed to by
45 * arguments 2-4. The compressed data is in storage internal to the
46 * chunk compressor, and it cannot be accessed beyond any subsequent
47 * calls to the chunk compressor.
49 * Chunks will be returned in the same order in which they were
50 * submitted for compression.
52 * The resulting compressed length may be up to the uncompressed length.
53 * In the case where they are equal, the returned data is actually the
54 * uncompressed data, not the compressed data.
56 * The return value is %true if a chunk of compressed data was
57 * successfully retrieved, or %false if there are no chunks currently
58 * being compressed. */
59 bool (*get_compression_result)(struct chunk_compressor *,
60 const void **, u32 *, u32 *);
64 /* Functions that return implementations of the chunk_compressor interface. */
66 #ifdef ENABLE_MULTITHREADED_COMPRESSION
68 new_parallel_chunk_compressor(int out_ctype, u32 out_chunk_size,
69 unsigned num_threads, u64 max_memory,
70 struct chunk_compressor **compressor_ret);
74 new_serial_chunk_compressor(int out_ctype, u32 out_chunk_size,
75 struct chunk_compressor **compressor_ret);
77 #endif /* _WIMLIB_CHUNK_COMPRESSOR_H */