Logo Search packages:      
Sourcecode: jamin version File versions

void jack_ringbuffer_get_write_vector ( const jack_ringbuffer_t *  rb,
jack_ringbuffer_data_t *  vec 
)

Fill a data structure with a description of the current writable space in the ringbuffer. The description is returned in a two element array of jack_ringbuffer_data_t. Two elements are needed because the space available for writing may be split across the end of the ringbuffer.

The first element will always contain a valid len field, which may be zero or greater. If the len field is non-zero, then data can be written in a contiguous fashion using the address given in the corresponding buf field.

If the second element has a non-zero len field, then a second contiguous stretch of data can be written to the address given in the corresponding buf field.

Parameters:
rb a pointer to the ringbuffer structure.
vec a pointer to a 2 element array of jack_ringbuffer_data_t.

Definition at line 280 of file ringbuffer.c.

{
  size_t free_cnt;
  size_t cnt2;
  size_t w, r;

  w = rb->write_ptr;
  r = rb->read_ptr;

  if (w > r) {
    free_cnt = ((r - w + rb->size) & rb->size_mask) - 1;
  } else if (w < r) {
    free_cnt = (r - w) - 1;
  } else {
    free_cnt = rb->size - 1;
  }

  cnt2 = w + free_cnt;

  if (cnt2 > rb->size) {

    /* Two part vector: the rest of the buffer after the current write
       ptr, plus some from the start of the buffer. */

    vec[0].buf = &(rb->buf[w]);
    vec[0].len = rb->size - w;
    vec[1].buf = rb->buf;
    vec[1].len = cnt2 & rb->size_mask;
  } else {
    vec[0].buf = &(rb->buf[w]);
    vec[0].len = free_cnt;
    vec[1].len = 0;
  }
}


Generated by  Doxygen 1.6.0   Back to index