Last active
March 3, 2026 07:20
-
-
Save russdill/88f1c9f816ea8159e59235bba45bbab9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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