42 #define CACHED_PAYLOAD_MAX 5
74 static
void free_fn_do_nothing(
void *data)
86 data_payload =
ast_calloc(1,
sizeof(*data_payload));
104 ast_assert(buffer != NULL);
106 buffer_space = buffer->
max - buffer->
count;
118 if (buffer_payload) {
124 ast_log(LOG_ERROR,
"Failed to allocate memory to the cache.");
133 if (buffer_payload) {
134 ast_free(buffer_payload);
139 ast_log(LOG_ERROR,
"Failed to remove memory from the cache.");
147 struct ast_data_buffer *buffer;
149 ast_assert(size != 0);
160 buffer->
free_fn = free_fn ? free_fn : free_fn_do_nothing;
172 ast_assert(buffer != NULL);
175 ast_assert(size > 0);
177 if (buffer->
max == size) {
182 if (buffer->
max > size) {
183 int remove = buffer->
max - size;
189 ast_free(existing_payload);
209 ast_assert(buffer != NULL);
210 ast_assert(payload != NULL);
222 buffer_payload->
pos =
pos;
224 if (!buffer_payload) {
233 buffer_payload->
pos =
pos;
235 if (!buffer_payload) {
242 if (existing_payload->
pos == pos) {
243 ast_debug(3,
"Packet with position %zu is already in buffer. Not inserting.\n", pos);
248 if (existing_payload->
pos > pos) {
256 if (inserted == -1) {
273 ast_assert(buffer != NULL);
276 if (buffer_payload->
pos == pos) {
277 return buffer_payload->
payload;
284 static void data_buffer_free_buffer_payload(
struct ast_data_buffer *buffer,
287 buffer_payload->
payload = NULL;
295 ast_free(buffer_payload);
303 ast_assert(buffer != NULL);
306 if (buffer_payload->
pos == pos) {
307 void *payload = buffer_payload->
payload;
310 data_buffer_free_buffer_payload(buffer, buffer_payload);
322 ast_assert(buffer != NULL);
324 if (buffer->
count > 0) {
329 payload = buffer_payload->
payload;
330 data_buffer_free_buffer_payload(buffer, buffer_payload);
342 ast_assert(buffer != NULL);
346 ast_free(buffer_payload);
350 ast_free(buffer_payload);
358 ast_assert(buffer != NULL);
360 return buffer->
count;
365 ast_assert(buffer != NULL);
Asterisk main include file. File version handling, generic pbx functions.
void(* ast_data_buffer_free_callback)(void *data)
A callback function to free a data payload in a data buffer.
Data buffer containing fixed number of data payloads.
String manipulation functions.
Payload entry placed inside of the data buffer list.
struct ast_data_buffer::@345 cached_payloads
A linked list of unused cached data payloads.
void * payload
The payload for this position.
struct ast_data_buffer::@344 payloads
A linked list of data payloads.
size_t pos
The provided position for this.
struct ast_data_buffer * ast_data_buffer_alloc(ast_data_buffer_free_callback free_fn, size_t size)
Allocate a data buffer.
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
size_t max
Maximum number of data payloads in the buffer.
#define CACHED_PAYLOAD_MAX
The number of payloads to increment the cache by.
void * ast_data_buffer_remove_head(struct ast_data_buffer *buffer)
Remove the first payload from the data buffer.
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
void * ast_data_buffer_remove(struct ast_data_buffer *buffer, size_t pos)
Remove a data payload from the data buffer.
A set of macros to manage forward-linked lists.
#define ast_debug(level,...)
Log a DEBUG message.
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
#define AST_LIST_HEAD_NOLOCK(name, type)
Defines a structure to be used to hold a list of specified type (with no lock).
void ast_data_buffer_free(struct ast_data_buffer *buffer)
Free a data buffer (and all held data payloads)
size_t ast_data_buffer_count(const struct ast_data_buffer *buffer)
Return the number of payloads in a data buffer.
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
size_t cache_count
The current number of data payloads in the cache.
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
void ast_data_buffer_resize(struct ast_data_buffer *buffer, size_t size)
Resize a data buffer.
#define ast_calloc(num, len)
A wrapper for calloc()
Support for logging to various files, console and syslog Configuration in file logger.conf.
size_t count
The current number of data payloads in the buffer.
size_t ast_data_buffer_max(const struct ast_data_buffer *buffer)
Return the maximum number of payloads a data buffer can hold.
void * ast_data_buffer_get(const struct ast_data_buffer *buffer, size_t pos)
Retrieve a data payload from the data buffer.
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
int ast_data_buffer_put(struct ast_data_buffer *buffer, size_t pos, void *payload)
Place a data payload at a position in the data buffer.
static struct data_buffer_payload_entry * data_buffer_payload_alloc(void *payload, size_t pos)
Helper function to allocate a data payload.
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
static void ast_data_buffer_cache_adjust(struct ast_data_buffer *buffer)
Helper function that sets the cache to its maximum number of payloads.
#define AST_LIST_INSERT_BEFORE_CURRENT(elm, field)
Inserts a list entry before the current entry during a traversal.
struct data_buffer_payload_entry::@343 list
Linked list information.
ast_data_buffer_free_callback free_fn
Callback function to free a data payload.