Skip to content

Instantly share code, notes, and snippets.

@russdill
Last active March 3, 2026 07:20
Show Gist options
  • Select an option

  • Save russdill/88f1c9f816ea8159e59235bba45bbab9 to your computer and use it in GitHub Desktop.

Select an option

Save russdill/88f1c9f816ea8159e59235bba45bbab9 to your computer and use it in GitHub Desktop.
#ifndef _QUEUE_H
#define _QUEUE_H
#include <ccan/array_size/array_size.h>
struct queue_idx {
unsigned int head;
unsigned int tail;
};
#define queue_push(array, idx, item) ({ \
(array)[(idx).head++ % ARRAY_SIZE(array)] = (item); \
})
#define queue_pop(array, idx) ({ \
(array)[(idx).tail++ % ARRAY_SIZE(array)]; \
})
#define queue_size(idx) ({ \
(idx)->head - (idx).tail; \
})
#define queue_free(array, idx) ({ \
ARRAY_SIZE(data) - queue_size(idx); \
})
#define queue_empty(idx) ({ !queue_size(idx); })
#define queue_full(array, idx) ({ !queue_free(array, idx); })
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment