#include <sys/types.h>Go to the source code of this file.
Functions | |
| ringbuffer_t * | ringbuffer_create (size_t sz) |
| void | ringbuffer_free (ringbuffer_t *rb) |
| void | ringbuffer_get_read_vector (const ringbuffer_t *rb, ringbuffer_data_t *vec) |
| void | ringbuffer_get_write_vector (const ringbuffer_t *rb, ringbuffer_data_t *vec) |
| size_t | ringbuffer_read (ringbuffer_t *rb, char *dest, size_t cnt) |
| size_t | ringbuffer_peek (ringbuffer_t *rb, char *dest, size_t cnt) |
| void | ringbuffer_read_advance (ringbuffer_t *rb, size_t cnt) |
| size_t | ringbuffer_read_space (const ringbuffer_t *rb) |
| int | ringbuffer_mlock (ringbuffer_t *rb) |
| void | ringbuffer_reset (ringbuffer_t *rb) |
| size_t | ringbuffer_write (ringbuffer_t *rb, const char *src, size_t cnt) |
| void | ringbuffer_write_advance (ringbuffer_t *rb, size_t cnt) |
| size_t | ringbuffer_write_space (const ringbuffer_t *rb) |
A set of library functions to make lock-free ringbuffers available to JACK clients. The `capture_client.c' (in the example_clients directory) is a fully functioning user of this API.
The key attribute of a ringbuffer is that it can be safely accessed by two threads simultaneously -- one reading from the buffer and the other writing to it -- without using any synchronization or mutual exclusion primitives. For this to work correctly, there can only be a single reader and a single writer thread. Their identities cannot be interchanged.
Definition in file ringbuffer.h.
| ringbuffer_t* ringbuffer_create | ( | size_t | sz | ) |
Allocates a ringbuffer data structure of a specified size. The caller must arrange for a call to ringbuffer_free() to release the memory associated with the ringbuffer.
| sz | the ringbuffer size in bytes. |
Definition at line 38 of file ringbuffer.cpp.
References ringbuffer_create().
Referenced by ringbuffer_create().
| void ringbuffer_free | ( | ringbuffer_t * | rb | ) |
Frees the ringbuffer data structure allocated by an earlier call to ringbuffer_create().
| rb | a pointer to the ringbuffer structure. |
Definition at line 61 of file ringbuffer.cpp.
References ringbuffer_free().
Referenced by ringbuffer_free().
| void ringbuffer_get_read_vector | ( | const ringbuffer_t * | rb, | |
| ringbuffer_data_t * | vec | |||
| ) |
Fill a data structure with a description of the current readable data held in the ringbuffer. This description is returned in a two element array of ringbuffer_data_t. Two elements are needed because the data to be read 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 read 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 read from the address given in its corresponding buf field.
| rb | a pointer to the ringbuffer structure. | |
| vec | a pointer to a 2 element array of ringbuffer_data_t. |
Definition at line 285 of file ringbuffer.cpp.
References ringbuffer_get_read_vector().
Referenced by ringbuffer_get_read_vector().
| void ringbuffer_get_write_vector | ( | const ringbuffer_t * | rb, | |
| 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 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.
| rb | a pointer to the ringbuffer structure. | |
| vec | a pointer to a 2 element array of ringbuffer_data_t. |
Definition at line 329 of file ringbuffer.cpp.
References ringbuffer_get_write_vector().
Referenced by ringbuffer_get_write_vector().
| int ringbuffer_mlock | ( | ringbuffer_t * | rb | ) |
Lock a ringbuffer data block into memory.
Uses the mlock() system call. This is not a realtime operation.
| rb | a pointer to the ringbuffer structure. |
Definition at line 75 of file ringbuffer.cpp.
References ringbuffer_mlock().
Referenced by ringbuffer_mlock().
| size_t ringbuffer_peek | ( | ringbuffer_t * | rb, | |
| char * | dest, | |||
| size_t | cnt | |||
| ) |
Read data from the ringbuffer. Opposed to ringbuffer_read() this function does not move the read pointer. Thus it's a convenient way to inspect data in the ringbuffer in a continous fashion. The price is that the data is copied into a user provided buffer. For "raw" non-copy inspection of the data in the ringbuffer use ringbuffer_get_read_vector().
| rb | a pointer to the ringbuffer structure. | |
| dest | a pointer to a buffer where data read from the ringbuffer will go. | |
| cnt | the number of bytes to read. |
Definition at line 181 of file ringbuffer.cpp.
References ringbuffer_peek(), and ringbuffer_read_space().
Referenced by ringbuffer_peek().
| size_t ringbuffer_read | ( | ringbuffer_t * | rb, | |
| char * | dest, | |||
| size_t | cnt | |||
| ) |
Read data from the ringbuffer.
| rb | a pointer to the ringbuffer structure. | |
| dest | a pointer to a buffer where data read from the ringbuffer will go. | |
| cnt | the number of bytes to read. |
Definition at line 140 of file ringbuffer.cpp.
References ringbuffer_read(), and ringbuffer_read_space().
Referenced by ringbuffer_read(), and VideoEncoder::thread_loop().
| void ringbuffer_read_advance | ( | ringbuffer_t * | rb, | |
| size_t | cnt | |||
| ) |
Advance the read pointer.
After data have been read from the ringbuffer using the pointers returned by ringbuffer_get_read_vector(), use this function to advance the buffer pointers, making that space available for future write operations.
| rb | a pointer to the ringbuffer structure. | |
| cnt | the number of bytes read. |
Definition at line 264 of file ringbuffer.cpp.
References ringbuffer_read_advance().
Referenced by ringbuffer_read_advance().
| size_t ringbuffer_read_space | ( | const ringbuffer_t * | rb | ) |
Return the number of bytes available for reading.
| rb | a pointer to the ringbuffer structure. |
Definition at line 101 of file ringbuffer.cpp.
References ringbuffer_read_space().
Referenced by ringbuffer_peek(), ringbuffer_read(), and ringbuffer_read_space().
| void ringbuffer_reset | ( | ringbuffer_t * | rb | ) |
Reset the read and write pointers, making an empty buffer.
This is not thread safe.
| rb | a pointer to the ringbuffer structure. |
Definition at line 90 of file ringbuffer.cpp.
References ringbuffer_reset().
Referenced by ringbuffer_reset().
| size_t ringbuffer_write | ( | ringbuffer_t * | rb, | |
| const char * | src, | |||
| size_t | cnt | |||
| ) |
Write data into the ringbuffer.
| rb | a pointer to the ringbuffer structure. | |
| src | a pointer to the data to be written to the ringbuffer. | |
| cnt | the number of bytes to write. |
Definition at line 225 of file ringbuffer.cpp.
References ringbuffer_write(), and ringbuffer_write_space().
Referenced by ringbuffer_write().
| void ringbuffer_write_advance | ( | ringbuffer_t * | rb, | |
| size_t | cnt | |||
| ) |
Advance the write pointer.
After data have been written the ringbuffer using the pointers returned by ringbuffer_get_write_vector(), use this function to advance the buffer pointer, making the data available for future read operations.
| rb | a pointer to the ringbuffer structure. | |
| cnt | the number of bytes written. |
Definition at line 273 of file ringbuffer.cpp.
References ringbuffer_write_advance().
Referenced by ringbuffer_write_advance().
| size_t ringbuffer_write_space | ( | const ringbuffer_t * | rb | ) |
Return the number of bytes available for writing.
| rb | a pointer to the ringbuffer structure. |
Definition at line 120 of file ringbuffer.cpp.
References ringbuffer_write_space().
Referenced by ringbuffer_write(), and ringbuffer_write_space().
1.6.1