34 #ifndef SORTQUEUE_H_DEFINED
35 #define SORTQUEUE_H_DEFINED
60 #define ADJUST_ROLLOVER_POINT 0x80000000
66 #define ADJUST_ROLLOVER_VALUE 0x10000
68 static inline int sq_lt_compare (
unsigned int a,
unsigned int b) {
81 static inline int sq_lte_compare (
unsigned int a,
unsigned int b) {
94 static inline int sq_init (
101 sq->
size = item_count;
107 sq->
items = malloc (item_count * size_per_item);
108 if (sq->
items == NULL) {
111 memset (sq->
items, 0, item_count * size_per_item);
113 if ((sq->
items_inuse = malloc (item_count *
sizeof (
unsigned int)))
121 memset (sq->
items_inuse, 0, item_count * sizeof (
unsigned int));
126 static inline void sq_reinit (
struct sq *sq,
unsigned int head_seqid)
137 static inline void sq_assert (
const struct sq *sq,
unsigned int pos)
143 for (i = sq->
pos_max + 1; i < sq->size; i++) {
147 static inline void sq_copy (
struct sq *sq_dest,
const struct sq *sq_src)
149 sq_assert (sq_src, 20);
164 static inline void sq_free (
struct sq *sq) {
170 static inline void *sq_item_add (
176 unsigned int sq_position;
179 if (sq_position > sq->
pos_max) {
197 static inline unsigned int sq_item_inuse (
199 unsigned int seq_id) {
201 unsigned int sq_position;
209 if (seq_id < sq->head_seqid) {
210 fprintf(stderr,
"sq_item_inuse: seqid %d, head %d\n",
219 static inline unsigned int sq_item_miss_count (
223 unsigned int sq_position;
230 static inline unsigned int sq_size_get (
236 static inline unsigned int sq_in_range (
254 if (seq_id < sq->head_seqid) {
265 static inline unsigned int sq_item_get (
271 unsigned int sq_position;
292 *sq_item_out = sq_item;
296 static inline void sq_items_release (
struct sq *sq,
unsigned int seqid)
298 unsigned int oldhead;
306 memset (&sq->
items_inuse[oldhead], 0, (sq->
size - oldhead) * sizeof (
unsigned int));
311 (seqid - sq->
head_seqid + 1) * sizeof (
unsigned int));
313 (seqid - sq->
head_seqid + 1) * sizeof (
unsigned int));