diff options
author | Matthias Vogelgesang <matthias.vogelgesang@kit.edu> | 2013-12-10 14:40:37 +0100 |
---|---|---|
committer | Matthias Vogelgesang <matthias.vogelgesang@kit.edu> | 2013-12-10 14:40:37 +0100 |
commit | 748407ebc8455f7df10c66790401c82e8a1ccd90 (patch) | |
tree | 6fe8b9d901c21c0052928fb9f03541dd39856c1e /bin/common/ring-buffer.c | |
parent | 5ad27e1abf2a19194adc238c125f7f595bac530f (diff) | |
download | uca-748407ebc8455f7df10c66790401c82e8a1ccd90.tar.gz uca-748407ebc8455f7df10c66790401c82e8a1ccd90.tar.bz2 uca-748407ebc8455f7df10c66790401c82e8a1ccd90.tar.xz uca-748407ebc8455f7df10c66790401c82e8a1ccd90.zip |
Make ring buffer public
Diffstat (limited to 'bin/common/ring-buffer.c')
-rw-r--r-- | bin/common/ring-buffer.c | 78 |
1 files changed, 0 insertions, 78 deletions
diff --git a/bin/common/ring-buffer.c b/bin/common/ring-buffer.c deleted file mode 100644 index 850dfc0..0000000 --- a/bin/common/ring-buffer.c +++ /dev/null @@ -1,78 +0,0 @@ - -#include <math.h> -#include "ring-buffer.h" - -RingBuffer * -ring_buffer_new (gsize block_size, - gsize n_blocks) -{ - RingBuffer *buffer; - - buffer = g_new0 (RingBuffer, 1); - buffer->block_size = block_size; - buffer->n_blocks_total = n_blocks; - buffer->n_blocks_used = 0; - buffer->current_index = 0; - buffer->data = g_malloc0_n (n_blocks, block_size); - - return buffer; -} - -void -ring_buffer_free (RingBuffer *buffer) -{ - g_free (buffer->data); - g_free (buffer); -} - -void -ring_buffer_reset (RingBuffer *buffer) -{ - buffer->n_blocks_used = 0; - buffer->current_index = 0; -} - -gsize -ring_buffer_get_block_size (RingBuffer *buffer) -{ - return buffer->block_size; -} - -gpointer -ring_buffer_get_current_pointer (RingBuffer *buffer) -{ - return buffer->data + (buffer->current_index % buffer->n_blocks_total) * buffer->block_size; -} - -void -ring_buffer_set_current_pointer (RingBuffer *buffer, - guint index) -{ - g_assert (index < buffer->n_blocks_total); - buffer->current_index = index; -} - -gpointer -ring_buffer_get_pointer (RingBuffer *buffer, - guint index) -{ - g_assert (index < buffer->n_blocks_total); - return buffer->data + ((buffer->current_index - buffer->n_blocks_used + index) % buffer->n_blocks_total) * buffer->block_size; -} - -guint -ring_buffer_get_num_blocks (RingBuffer *buffer) -{ - return buffer->n_blocks_used; -} - -void -ring_buffer_proceed (RingBuffer *buffer) -{ - buffer->current_index++; - - if (buffer->n_blocks_used < buffer->n_blocks_total) - buffer->n_blocks_used++; - else - buffer->current_index = buffer->current_index % buffer->n_blocks_total; -} |