f93eeb6cebabc4e58be696f237e32ebe0b189415
[archipelago] / xseg / xq / xq.h
1 #ifndef _XQ_H
2 #define _XQ_H
3
4 typedef unsigned int xqindex;
5
6 #define None (xqindex)-1
7
8 #include <sys/util.h>
9 #include "xq_lock.h"
10
11 struct xq {
12         struct xq_lock lock;
13         xqindex head, tail;
14         xqindex *queue;
15         xqindex size;
16 };
17
18 xqindex    * xq_alloc_empty  ( struct xq  * xq,
19                                xqindex      size );
20
21 void         xq_init_empty   ( struct xq  * xq,
22                                xqindex      size,
23                                void       * mem );
24
25 xqindex    * xq_alloc_map    ( struct xq  * xq,
26                                xqindex      size,
27                                xqindex      count,
28                                xqindex   (* mapfn ) (xqindex) );
29
30 void         xq_init_map     ( struct xq  * xq,
31                                xqindex      size,
32                                xqindex      count,
33                                xqindex   (* mapfn ) (xqindex),
34                                void       * mem );
35
36 xqindex    * xq_alloc_seq    ( struct xq  * xq,
37                                xqindex      size,
38                                xqindex      count );
39
40 void         xq_init_seq     ( struct xq  * xq,
41                                xqindex      size,
42                                xqindex      count,
43                                void       * mem );
44
45 void         xq_free         ( struct xq  * xq  );
46
47 xqindex      xq_append_head  ( struct xq  * xq,
48                                xqindex      xqi );
49
50 xqindex      xq_pop_head     ( struct xq  * xq  );
51
52 xqindex      xq_append_tail  ( struct xq  * xq,
53                                xqindex      xqi );
54
55 xqindex      xq_pop_tail     ( struct xq  * xq  );
56
57 int          xq_head_to_tail ( struct xq  * hq,
58                                struct xq  * tq,
59                                xqindex      nr  );
60
61 xqindex      xq_size         ( struct xq  * xq  );
62
63 xqindex      xq_count        ( struct xq  * xq  );
64
65 void         xq_print        ( struct xq  * xq  );
66
67 #endif
68