Logo Search packages:      
Sourcecode: jamin version File versions

jack_ringbuffer_t* jack_ringbuffer_create ( size_t  sz  ) 

Allocates a ringbuffer data structure of a specified size. The caller must arrange for a call to jack_ringbuffer_free() to release the memory associated with the ringbuffer.

Parameters:
sz the ringbuffer size in bytes.
Returns:
a pointer to a new jack_ringbuffer_t, if successful; NULL otherwise.

Definition at line 39 of file ringbuffer.c.

{
  int power_of_two;
  jack_ringbuffer_t *rb;

  rb = malloc (sizeof (jack_ringbuffer_t));

  for (power_of_two = 1; 1 << power_of_two < sz; power_of_two++);

  rb->size = 1 << power_of_two;
  rb->size_mask = rb->size;
  rb->size_mask -= 1;
  rb->write_ptr = 0;
  rb->read_ptr = 0;
  rb->buf = malloc (rb->size);
  rb->mlocked = 0;

  return rb;
}


Generated by  Doxygen 1.6.0   Back to index