ringbuffer: fix the ambiguous name

RT_RINGBUFFER_SIZE could mean "the size of the whole buffer", "the size
of the empty space" or "the size of the data". Moreover, it's never a
micro anymore. Change it to rt_ringbuffer_data_len before it's too late.
Also, RT_RINGBUFFER_EMPTY is changed to rt_ringbuffer_space_len.
This commit is contained in:
Grissiom
2013-08-19 10:50:20 +08:00
parent 6f75988cee
commit 981d929b56
3 changed files with 36 additions and 35 deletions

View File

@@ -45,9 +45,9 @@ struct rt_ringbuffer
/* use the msb of the {read,write}_index as mirror bit. You can see this as
* if the buffer adds a virtual mirror and the pointers point either to the
* normal or to the mirrored buffer. If the write_index has the same value
* with the read_index, but in differenct mirro, the buffer is full. While
* if the write_index and the read_index are the same and within the same
* mirror, the buffer is empty. The ASCII art of the ringbuffer is:
* with the read_index, but in a different mirror, the buffer is full.
* While if the write_index and the read_index are the same and within the
* same mirror, the buffer is empty. The ASCII art of the ringbuffer is:
*
* mirror = 0 mirror = 1
* +---+---+---+---+---+---+---+|+~~~+~~~+~~~+~~~+~~~+~~~+~~~+
@@ -73,29 +73,6 @@ struct rt_ringbuffer
rt_int16_t buffer_size;
};
/** return the size of data in rb */
rt_inline rt_uint16_t RT_RINGBUFFER_SIZE(struct rt_ringbuffer *rb)
{
if (rb->read_index == rb->write_index)
{
if (rb->read_mirror == rb->write_mirror)
/* we are in the same side, the ringbuffer is empty. */
return 0;
else
return rb->buffer_size;
}
else
{
if (rb->write_index > rb->read_index)
return rb->write_index - rb->read_index;
else
return rb->buffer_size - (rb->read_index - rb->write_index);
}
}
/** return the size of empty space in rb */
#define RT_RINGBUFFER_EMPTY(rb) ((rb)->buffer_size - RT_RINGBUFFER_SIZE(rb))
/* pipe device */
#define PIPE_DEVICE(device) ((struct rt_pipe_device*)(device))
struct rt_pipe_device
@@ -163,12 +140,36 @@ rt_size_t rt_ringbuffer_get(struct rt_ringbuffer *rb,
rt_uint8_t *ptr,
rt_uint16_t length);
rt_size_t rt_ringbuffer_getchar(struct rt_ringbuffer *rb, rt_uint8_t *ch);
rt_inline rt_uint16_t rt_ringbuffer_get_size(struct rt_ringbuffer *rb)
{
RT_ASSERT(rb != RT_NULL);
return rb->buffer_size;
}
/** return the size of data in rb */
rt_inline rt_uint16_t rt_ringbuffer_data_len(struct rt_ringbuffer *rb)
{
if (rb->read_index == rb->write_index)
{
if (rb->read_mirror == rb->write_mirror)
/* we are in the same side, the ringbuffer is empty. */
return 0;
else
return rb->buffer_size;
}
else
{
if (rb->write_index > rb->read_index)
return rb->write_index - rb->read_index;
else
return rb->buffer_size - (rb->read_index - rb->write_index);
}
}
/** return the size of empty space in rb */
#define rt_ringbuffer_space_len(rb) ((rb)->buffer_size - rt_ringbuffer_data_len(rb))
/**
* Pipe Device
*/