rpm  5.4.15
rpmzq.h
Go to the documentation of this file.
1 #ifndef _H_RPMZQ_
2 #define _H_RPMZQ_
3 
9 #include <popt.h>
10 
11 #include <yarn.h>
12 
15 typedef /*@abstract@*/ struct rpmzSpace_s * rpmzSpace;
16 
19 typedef /*@abstract@*/ struct rpmzPool_s * rpmzPool;
20 
23 typedef /*@abstract@*/ struct rpmzQueue_s * rpmzQueue;
24 
27 typedef /*@abstract@*/ /*@refcounted@*/ struct rpmzJob_s * rpmzJob;
28 
29 typedef struct rpmzFIFO_s * rpmzFIFO;
30 typedef struct rpmzSEQ_s * rpmzSEQ;
31 
34 /*@-redecl@*/
35 /*@unchecked@*/
36 extern int _rpmzq_debug;
37 /*@=redecl@*/
38 
41 /*@unchecked@*/
42 extern rpmzQueue _rpmzq;
43 
46 /*@unchecked@*/ /*@observer@*/
47 extern struct poptOption rpmzqOptionsPoptTable[];
48 
51 enum rpmzMode_e {
55 };
56 
69 };
70 
71 #define _ZKFB(n) (1U << (n))
72 #define _ZFB(n) (_ZKFB(n) | 0x40000000)
73 
79  /* 1 unused */
83  /* XXX compressor specific flags need to be set some other way. */
84  /* XXX unused */
88  /* XXX logic is reversed, disablers should clear with toggle. */
92  /* XXX unimplemented */
94  /* XXX logic is reversed. */
102 #define RPMZ_FLAGS_FORCE \
103  (RPMZ_FLAGS_OVERWRITE|RPMZ_FLAGS_ALREADY|RPMZ_FLAGS_SYMLINKS|RPMZ_FLAGS_TTY)
104 
105 #ifdef NOTYET
106  RPMZ_FLAGS_SUBBLOCK = INT_MIN,
107  RPMZ_FLAGS_DELTA,
108  RPMZ_FLAGS_LZMA1,
109  RPMZ_FLAGS_LZMA2,
110 #endif
111 
118 
119 };
120 
121 #ifdef _RPMZQ_INTERNAL
122 
123 struct rpmzSpace_s {
124  yarnLock use;
125  void *ptr;
126  size_t ix;
127  unsigned char *buf;
128  size_t len;
129  rpmzPool pool;
130  rpmzSpace next;
131 };
132 
134 struct rpmzPool_s {
135  yarnLock have;
136 /*@relnull@*/
137  rpmzSpace head;
138  size_t size;
139  int limit;
140  int made;
141 };
142 
145 struct rpmzJob_s {
146  yarnLock use;
147  long seq;
148  int more;
149 /*@relnull@*/
150  rpmzSpace in;
151 /*@relnull@*/
152  rpmzSpace out;
153  unsigned long check;
154  yarnLock calc;
155 /*@null@*/
156  rpmzJob next;
157 };
158 
161 typedef struct rpmzh_s * rpmzh;
162 
165 struct rpmzh_s {
166 /*@observer@*/ /*@null@*/
167  const char * name;
168  time_t mtime;
169  unsigned long head;
170  unsigned long ulen;
171  unsigned long clen;
172  unsigned long check;
173 /* saved gzip/zip header data for decompression, testing, and listing */
174 /*@only@*/ /*@null@*/
175  char * hname;
176  time_t stamp;
177  /* XXX zip_head?!? */
178  unsigned long zip_ulen;
179  unsigned long zip_clen;
180  unsigned long zip_crc;
181 };
182 
185 struct rpmzFIFO_s {
186 /*@only@*/ /*@null@*/
187  yarnLock have;
188 /*@null@*/
189  rpmzJob head;
190 /*@shared@*/
191  rpmzJob * tail;
192 };
193 
196 struct rpmzSEQ_s {
197 /*@only@*/ /*@null@*/
198  yarnLock first;
199 /*@null@*/
200  rpmzJob head;
201 };
202 
205 typedef struct rpmzi_s * rpmzi;
206 struct rpmzi_s {
207 /*@only@*/ /*@null@*/
208  yarnLock state;
209 /*@only@*/ /*@null@*/
210  yarnThread reader;
211  off_t in_tot;
212  int cnt;
213 /*@relnull@*/
214  rpmzFIFO q;
215 /*@relnull@*/
216  rpmzPool pool;
217 };
218 
221 typedef struct rpmzo_s * rpmzo;
222 struct rpmzo_s {
223 /*@only@*/ /*@null@*/
224  yarnLock wstate;
225  yarnThread _writer;
226 /*@only@*/ /*@null@*/
227  yarnLock kstate;
228  yarnThread _checker;
229  off_t out_tot;
230 /*@relnull@*/
231  rpmzFIFO q;
232 /*@relnull@*/
233  rpmzPool pool;
234 };
235 
238 typedef struct rpmzc_s * rpmzc;
239 struct rpmzc_s {
240  enum rpmzFlags_e flags;
241  enum rpmzFormat_e format;
242  enum rpmzMode_e mode;
244  unsigned int level;
245  unsigned int threads;
246  size_t blocksize;
248  mode_t omode;
250  int cthreads;
251 /*@relnull@*/
252  rpmzFIFO q;
253 /*@relnull@*/
254  rpmzPool pool;
255 };
256 
259 typedef struct rpmzw_s * rpmzw;
260 struct rpmzw_s {
261 /*@only@*/ /*@null@*/
262  yarnThread thread;
263  rpmzSEQ q;
264 /*@relnull@*/
265  rpmzPool pool;
266 };
267 
270 typedef struct rpmzf_s * rpmzf;
271 struct rpmzf_s {
272 /*@null@*/
273  const char * fn;
274  int fdno;
275 };
276 
279 struct rpmzQueue_s {
280 /* --- globals (modified by main thread only when it's the only thread) */
281  enum rpmzFlags_e flags;
282  enum rpmzFormat_e format;
283  enum rpmzMode_e mode;
284  unsigned int level;
285  unsigned int threads;
286  /* XXX popt has sizeof(size_t) != sizeof(unsigned int) issues */
287  unsigned int blocksize;
289 /*@null@*/ /*@observer@*/
290  const char * suffix;
291  int verbosity;
293  struct timeval start;
294 /*@refcounted@*/ /*@null@*/
295  rpmzLog zlog;
297  struct rpmzf_s _zinp;
298  struct rpmzf_s _zout;
299 
300  off_t in_tot;
301  off_t out_tot;
303  struct rpmzc_s _zc;
304  struct rpmzw_s _zw;
306  struct rpmzi_s _zi;
307  struct rpmzo_s _zo;
309  mode_t omode;
311 #ifndef DYING /* XXX this cruft is going away */
312  long lastseq;
313  size_t iblocksize;
314  int ilimit;
315  size_t oblocksize;
316  int olimit;
317 #endif
318 /*@only@*/ /*@relnull@*/
319  rpmzh _zh;
321 /* --- globals for decompression and listing buffered reading */
322  int _in_which;
324 #define IN_BUF_ALLOCATED 32768U /* input buffer size */
325  size_t _in_buf_allocated;
326 
327 };
328 #endif /* _RPMZQ_INTERNAL */
329 
330 #ifdef __cplusplus
331 extern "C" {
332 #endif
333 
336 int rpmbzCompressBlock(void * _bz, rpmzJob job)
337  /*@globals fileSystem @*/
338  /*@modifies job, fileSystem @*/;
339 
340 /* -- pool of spaces for buffer management -- */
341 
342 /* These routines manage a pool of spaces. Each pool specifies a fixed size
343  buffer to be contained in each space. Each space has a use count, which
344  when decremented to zero returns the space to the pool. If a space is
345  requested from the pool and the pool is empty, a space is immediately
346  created unless a specified limit on the number of spaces has been reached.
347  Only if the limit is reached will it wait for a space to be returned to the
348  pool. Each space knows what pool it belongs to, so that it can be returned.
349  */
350 
351 /* initialize a pool (pool structure itself provided, not allocated) -- the
352  limit is the maximum number of spaces in the pool, or -1 to indicate no
353  limit, i.e., to never wait for a buffer to return to the pool */
354 rpmzPool rpmzqNewPool(size_t size, int limit)
355  /*@globals fileSystem, internalState @*/
356  /*@modifies fileSystem, internalState @*/;
357 
363 rpmzSpace rpmzqNewSpace(/*@null@*/ rpmzPool pool, size_t len)
364  /*@globals fileSystem, internalState @*/
365  /*@modifies pool, fileSystem, internalState @*/;
366 
371 void rpmzqUseSpace(rpmzSpace space)
372  /*@globals fileSystem, internalState @*/
373  /*@modifies space, fileSystem, internalState @*/;
374 
379 /*@null@*/
380 rpmzSpace rpmzqDropSpace(/*@only@*/ /*@null@*/ rpmzSpace space)
381  /*@globals fileSystem, internalState @*/
382  /*@modifies space, fileSystem, internalState @*/;
383 
384 /* free the memory and lock resources of a pool -- return number of spaces for
385  debugging and resource usage measurement */
386 /*@null@*/
387 rpmzPool rpmzqFreePool(/*@only@*/ rpmzPool pool, /*@null@*/ int *countp)
388  /*@globals fileSystem, internalState @*/
389  /*@modifies pool, *countp, fileSystem, internalState @*/;
390 
393 /*@null@*/
394 rpmzJob rpmzqFreeJob(/*@killref@*/ rpmzJob job)
395  /*@globals fileSystem, internalState @*/
396  /*@modifies job, fileSystem, internalState @*/;
397 
400 /*@newref@*/
401 rpmzJob rpmzqNewJob(long seq)
402  /*@globals fileSystem, internalState @*/
403  /*@modifies fileSystem, internalState @*/;
404 
407 /*@newref@*/ /*@null@*/
408 rpmzJob rpmzqUseJob(/*@null@*/ rpmzJob job)
409  /*@globals fileSystem, internalState @*/
410  /*@modifies job, fileSystem, internalState @*/;
411 
414 /*@null@*/
415 rpmzJob rpmzqDropJob(/*@killref@*/ /*@null@*/ rpmzJob job)
416  /*@globals fileSystem, internalState @*/
417  /*@modifies job, fileSystem, internalState @*/;
418 
419 /* compress or write job (passed from compress list to write list) -- if seq is
420  equal to -1, rpmzqCompressThread() is instructed to return; if more is false then
421  this is the last chunk, which after writing tells write_thread to return */
422 
425 void rpmzqFini(rpmzQueue zq)
426  /*@globals fileSystem, internalState @*/
427  /*@modifies zq, fileSystem, internalState @*/;
428 
430 void rpmzqInit(rpmzQueue zq)
431  /*@globals fileSystem, internalState @*/
432  /*@modifies zq, fileSystem, internalState @*/;
433 
436 /*@null@*/
437 rpmzQueue rpmzqFree(/*@only@*/ rpmzQueue zq)
438  /*@*/;
439 
442 rpmzQueue rpmzqNew(/*@returned@*/rpmzQueue zq, rpmzLog zlog, int limit)
443  /*@modifies zq @*/;
444 
447 rpmzFIFO rpmzqInitFIFO(long val)
448  /*@globals fileSystem, internalState @*/
449  /*@modifies fileSystem, internalState @*/;
450 
453 /*@null@*/
454 rpmzFIFO rpmzqFiniFIFO(/*@only@*/ rpmzFIFO zs)
455  /*@globals fileSystem, internalState @*/
456  /*@modifies zs, fileSystem, internalState @*/;
457 
460 void rpmzqVerifyFIFO(/*@null@*/ rpmzFIFO zs)
461  /*@globals fileSystem, internalState @*/
462  /*@modifies zs, fileSystem, internalState @*/;
463 
466 /*@null@*/
468  /*@globals fileSystem, internalState @*/
469  /*@modifies zs, fileSystem, internalState @*/;
470 
473 void rpmzqAddFIFO(rpmzFIFO zs, rpmzJob job)
474  /*@globals fileSystem, internalState @*/
475  /*@modifies zs, job, fileSystem, internalState @*/;
476 
479 rpmzSEQ rpmzqInitSEQ(long val)
480  /*@globals fileSystem, internalState @*/
481  /*@modifies fileSystem, internalState @*/;
482 
485 /*@null@*/
486 rpmzSEQ rpmzqFiniSEQ(/*@only@*/ rpmzSEQ zs)
487  /*@globals fileSystem, internalState @*/
488  /*@modifies zs, fileSystem, internalState @*/;
489 
492 void rpmzqVerifySEQ(/*@null@*/ rpmzSEQ zs)
493  /*@globals fileSystem, internalState @*/
494  /*@modifies zs, fileSystem, internalState @*/;
495 
498 rpmzJob rpmzqDelSEQ(rpmzSEQ zs, long seq)
499  /*@globals fileSystem, internalState @*/
500  /*@modifies zs, fileSystem, internalState @*/;
501 
504 void rpmzqAddSEQ(rpmzSEQ zs, rpmzJob job)
505  /*@globals fileSystem, internalState @*/
506  /*@modifies zs, job, fileSystem, internalState @*/;
507 
510 /*@null@*/
512  /*@globals fileSystem, internalState @*/
513  /*@modifies zq, fileSystem, internalState @*/;
514 
517 void rpmzqAddCJob(rpmzQueue zq, rpmzJob job)
518  /*@globals fileSystem, internalState @*/
519  /*@modifies zq, job, fileSystem, internalState @*/;
520 
523 rpmzJob rpmzqDelWJob(rpmzQueue zq, long seq)
524  /*@globals fileSystem, internalState @*/
525  /*@modifies zq, fileSystem, internalState @*/;
526 
529 void rpmzqAddWJob(rpmzQueue zq, rpmzJob job)
530  /*@globals fileSystem, internalState @*/
531  /*@modifies zq, job, fileSystem, internalState @*/;
532 
534 void rpmzqLaunch(rpmzQueue zq, long seq, unsigned int threads)
535  /*@globals fileSystem, internalState @*/
536  /*@modifies zq, fileSystem, internalState @*/;
537 
539 void rpmzqVerify(rpmzQueue zq)
540  /*@globals fileSystem, internalState @*/
541  /*@modifies zq, fileSystem, internalState @*/;
542 
543 #ifdef __cplusplus
544 }
545 #endif
546 
547 #endif /* _H_RPMZQ_ */
static const char * suffix[]
Definition: rpmgrep.c:188
rpmzFIFO rpmzqInitFIFO(long val)
void rpmzqAddCJob(rpmzQueue zq, rpmzJob job)
const char const char size_t len
Definition: bson.h:823
void rpmzqLaunch(rpmzQueue zq, long seq, unsigned int threads)
start another compress/decompress thread if needed
struct rpmzJob_s * rpmzJob
Definition: rpmzq.h:27
rpmzJob rpmzqDelWJob(rpmzQueue zq, long seq)
rpmzSEQ rpmzqFiniSEQ(rpmzSEQ zs)
rpmzJob rpmzqFreeJob(rpmzJob job)
rpmzSpace rpmzqNewSpace(rpmzPool pool, size_t len)
Get a space from a pool (or malloc if pool == NULL).
struct rpmzQueue_s * rpmzQueue
Definition: rpmzq.h:23
rpmzPool rpmzqFreePool(rpmzPool pool, int *countp)
rpmzQueue rpmzqNew(rpmzQueue zq, rpmzLog zlog, int limit)
#define _ZFB(n)
Definition: rpmzq.h:72
static yarnThread threads
Definition: yarn.c:358
int rpmbzCompressBlock(void *_bz, rpmzJob job)
const char * mode
Definition: mongo.h:440
void rpmzqUseSpace(rpmzSpace space)
Increment the use count to require one more drop before returning this space to the pool...
struct rpmzSEQ_s * rpmzSEQ
Definition: rpmzq.h:30
rpmzPool rpmzqNewPool(size_t size, int limit)
void rpmzqAddWJob(rpmzQueue zq, rpmzJob job)
struct rpmzLog_s * rpmzLog
trace log pointer
Definition: rpmzlog.h:11
const char const bson const bson int limit
Definition: mongo.h:569
rpmzFormat_e
Definition: rpmzq.h:59
void rpmzqVerifySEQ(rpmzSEQ zs)
rpmzJob rpmzqUseJob(rpmzJob job)
struct rpmzPool_s * rpmzPool
Definition: rpmzq.h:19
int _rpmzq_debug
rpmzJob rpmzqDelCJob(rpmzQueue zq)
rpmzJob rpmzqDelFIFO(rpmzFIFO zs)
void rpmzqAddFIFO(rpmzFIFO zs, rpmzJob job)
struct rpmzSpace_s * rpmzSpace
Definition: rpmzq.h:15
void rpmzqAddSEQ(rpmzSEQ zs, rpmzJob job)
const char const bson int mongo_write_concern int flags
Definition: mongo.h:485
rpmzJob rpmzqNewJob(long seq)
void rpmzqFini(rpmzQueue zq)
command the compress threads to all return, then join them all (call from main thread), free all the thread-related resources
rpmzQueue rpmzqFree(rpmzQueue zq)
struct poptOption rpmzqOptionsPoptTable[]
rpmzJob rpmzqDropJob(rpmzJob job)
const char const bson const bson bson * out
Definition: mongo.h:678
rpmzQueue _rpmzq
rpmzSpace rpmzqDropSpace(rpmzSpace space)
Drop a space, returning to the pool (or free'ing if no pool) when the use count is zero...
const char const char size_t size
Definition: bson.h:895
rpmzJob rpmzqDelSEQ(rpmzSEQ zs, long seq)
rpmzFIFO rpmzqFiniFIFO(rpmzFIFO zs)
const bson * in
Definition: bson.h:746
rpmzFlags_e
Definition: rpmzq.h:76
rpmzSEQ rpmzqInitSEQ(long val)
static const char * name
struct rpmzFIFO_s * rpmzFIFO
Definition: rpmzq.h:29
void rpmzqVerify(rpmzQueue zq)
verify no more jobs, prepare for next use
rpmzMode_e
Definition: rpmzq.h:51
void rpmzqInit(rpmzQueue zq)
setup job lists (call from main thread)
void rpmzqVerifyFIFO(rpmzFIFO zs)