Add functions for working with queues of bytes.

This is used by the IAP code.
This commit is contained in:
Richard Osborne
2013-12-09 18:21:50 +00:00
parent 4b6b98af10
commit e7ade114d6
2 changed files with 13 additions and 0 deletions

View File

@@ -43,6 +43,17 @@ inline unsigned queue_pop_word(queue_t &q, unsigned array[]) {
return array[q.rdptr++ & q.mask]; return array[q.rdptr++ & q.mask];
} }
inline void queue_push_byte(queue_t &q, unsigned char array[], unsigned data)
{
assert(!queue_is_full(q));
array[q.wrptr++ & q.mask] = data;
}
inline unsigned queue_pop_byte(queue_t &q, unsigned char array[]) {
assert(!queue_is_empty(q));
return array[q.rdptr++ & q.mask];
}
inline unsigned queue_items(const queue_t &q) { inline unsigned queue_items(const queue_t &q) {
return q.wrptr - q.rdptr; return q.wrptr - q.rdptr;
} }

View File

@@ -7,5 +7,7 @@ extern inline int queue_is_empty(const queue_t &q);
extern inline int queue_is_full(const queue_t &q); extern inline int queue_is_full(const queue_t &q);
extern inline void queue_push_word(queue_t &q, unsigned array[], unsigned data); extern inline void queue_push_word(queue_t &q, unsigned array[], unsigned data);
extern inline unsigned queue_pop_word(queue_t &q, unsigned array[]); extern inline unsigned queue_pop_word(queue_t &q, unsigned array[]);
extern inline void queue_push_byte(queue_t &q, unsigned char array[], unsigned data);
extern inline unsigned queue_pop_byte(queue_t &q, unsigned char array[]);
extern inline unsigned queue_space(const queue_t &q); extern inline unsigned queue_space(const queue_t &q);
extern inline unsigned queue_items(const queue_t &q); extern inline unsigned queue_items(const queue_t &q);