2010-07-19 16:05:18 -05:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CIRCULAR_BUFFER_H
|
|
|
|
#define CIRCULAR_BUFFER_H
|
|
|
|
|
|
|
|
class
|
2011-07-18 14:02:26 -05:00
|
|
|
circular_buffer : public kernel_owned<circular_buffer> {
|
2011-12-20 22:57:04 -06:00
|
|
|
static const size_t INITIAL_CIRCULAR_BUFFER_SIZE_IN_UNITS = 8;
|
2010-07-19 16:05:18 -05:00
|
|
|
|
2011-06-27 21:15:03 -05:00
|
|
|
public:
|
2011-07-18 14:02:26 -05:00
|
|
|
rust_kernel *kernel;
|
2010-07-28 01:51:04 -05:00
|
|
|
// Size of the data unit in bytes.
|
|
|
|
const size_t unit_sz;
|
2011-07-18 14:02:26 -05:00
|
|
|
circular_buffer(rust_kernel *kernel, size_t unit_sz);
|
2010-07-19 16:05:18 -05:00
|
|
|
~circular_buffer();
|
|
|
|
void transfer(void *dst);
|
|
|
|
void enqueue(void *src);
|
|
|
|
void dequeue(void *dst);
|
2010-07-28 02:01:06 -05:00
|
|
|
uint8_t *peek();
|
2010-07-19 16:05:18 -05:00
|
|
|
bool is_empty();
|
2010-08-11 18:08:26 -05:00
|
|
|
size_t size();
|
2010-07-19 16:05:18 -05:00
|
|
|
|
|
|
|
private:
|
2011-01-08 17:52:37 -06:00
|
|
|
size_t initial_size();
|
|
|
|
void grow();
|
|
|
|
void shrink();
|
|
|
|
|
2011-01-08 17:19:55 -06: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
|
|
|
|
|
|
|
// 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;
|
|
|
|
};
|
|
|
|
|
2011-01-08 17:19:55 -06:00
|
|
|
//
|
|
|
|
// Local Variables:
|
|
|
|
// mode: C++
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
2011-07-13 15:51:20 -05:00
|
|
|
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
|
2011-01-08 17:19:55 -06:00
|
|
|
// End:
|
|
|
|
//
|
|
|
|
|
2010-07-19 16:05:18 -05:00
|
|
|
#endif /* CIRCULAR_BUFFER_H */
|