]> wimlib.net Git - wimlib/blob - include/wimlib/chunk_compressor.h
x86_cpu_features.c: cpuid fix for x86_32 PIC with old GCC versions
[wimlib] / include / wimlib / chunk_compressor.h
1 /*
2  * chunk_compressor.h
3  *
4  * Interface for serial/parallel chunk compression.
5  */
6
7 #ifndef _WIMLIB_CHUNK_COMPRESSOR_H
8 #define _WIMLIB_CHUNK_COMPRESSOR_H
9
10 #include "wimlib/types.h"
11
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
16  * chunks).  */
17 struct chunk_compressor {
18         /* Variables set by the chunk compressor when it is created.  */
19         int out_ctype;
20         u32 out_chunk_size;
21         unsigned num_threads;
22
23         /* Free the chunk compressor.  */
24         void (*destroy)(struct chunk_compressor *);
25
26         /* Try to borrow a buffer into which the uncompressed data for the next
27          * chunk should be prepared.
28          *
29          * Only one buffer can be borrowed at a time.
30          *
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 *);
35
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);
40
41         /* Get the next chunk of compressed data.
42          *
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.
48          *
49          * Chunks will be returned in the same order in which they were
50          * submitted for compression.
51          *
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.
55          *
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 *);
61 };
62
63
64 /* Functions that return implementations of the chunk_compressor interface.  */
65
66 #ifdef ENABLE_MULTITHREADED_COMPRESSION
67 int
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);
71 #endif
72
73 int
74 new_serial_chunk_compressor(int out_ctype, u32 out_chunk_size,
75                             struct chunk_compressor **compressor_ret);
76
77 #endif /* _WIMLIB_CHUNK_COMPRESSOR_H  */