2010-07-19 16:05:18 -05:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CIRCULAR_BUFFER_H
|
|
|
|
#define CIRCULAR_BUFFER_H
|
|
|
|
|
|
|
|
class
|
|
|
|
circular_buffer : public dom_owned<circular_buffer> {
|
|
|
|
static const size_t INITIAL_CIRCULAR_BUFFFER_SIZE_IN_UNITS = 8;
|
|
|
|
static const size_t MAX_CIRCULAR_BUFFFER_SIZE = 1 << 24;
|
|
|
|
|
|
|
|
public:
|
|
|
|
rust_dom *dom;
|
|
|
|
circular_buffer(rust_dom *dom, size_t unit_sz);
|
|
|
|
~circular_buffer();
|
|
|
|
void transfer(void *dst);
|
|
|
|
void enqueue(void *src);
|
|
|
|
void dequeue(void *dst);
|
|
|
|
bool is_empty();
|
|
|
|
|
|
|
|
private:
|
2010-07-19 19:33:50 -05:00
|
|
|
// Size of the buffer in bytes.
|
2010-07-19 16:05:18 -05:00
|
|
|
size_t _buffer_sz;
|
2010-07-19 19:33:50 -05:00
|
|
|
|
|
|
|
// Size of the data unit in bytes.
|
|
|
|
size_t _unit_sz;
|
|
|
|
|
|
|
|
// Byte offset within the buffer where to read the next unit of data.
|
2010-07-19 16:05:18 -05:00
|
|
|
size_t _next;
|
2010-07-19 19:33:50 -05:00
|
|
|
|
|
|
|
// Number of bytes that have not been read from the buffer.
|
2010-07-19 16:05:18 -05:00
|
|
|
size_t _unread;
|
2010-07-19 19:33:50 -05:00
|
|
|
|
|
|
|
// The buffer itself.
|
2010-07-19 16:05:18 -05:00
|
|
|
uint8_t *_buffer;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* CIRCULAR_BUFFER_H */
|