Newer
Older
/* Attempt to get a frame from this thread's cache */
if ((iax_frames = ast_threadstorage_get(&frame_cache, sizeof(*iax_frames)))) {
AST_LIST_TRAVERSE_SAFE_BEGIN(iax_frames, fr, list) {
if (fr->afdatalen >= datalen) {
size_t afdatalen = fr->afdatalen;
AST_LIST_REMOVE_CURRENT(iax_frames, list);
memset(fr, 0, sizeof(*fr));
break;
}
}
AST_LIST_TRAVERSE_SAFE_END
}
if (!fr) {
if (!(fr = ast_calloc_cache(1, sizeof(*fr) + datalen)))
#else
if (!(fr = ast_calloc(1, sizeof(*fr) + datalen)))
return NULL;
fr->direction = direction;
fr->retrans = -1;
if (fr->direction == DIRECTION_INGRESS)
ast_atomic_fetchadd_int(&iframes, 1);
else
ast_atomic_fetchadd_int(&oframes, 1);
ast_atomic_fetchadd_int(&frames, 1);
void iax_frame_free(struct iax_frame *fr)
/* Note: does not remove from scheduler! */
if (fr->direction == DIRECTION_INGRESS)
ast_atomic_fetchadd_int(&iframes, -1);
ast_atomic_fetchadd_int(&oframes, -1);
else {
errorf("Attempt to double free frame detected\n");
return;
}
ast_atomic_fetchadd_int(&frames, -1);
if (!fr->cacheable || !(iax_frames = ast_threadstorage_get(&frame_cache, sizeof(*iax_frames)))) {
Tilghman Lesher
committed
ast_free(fr);
AST_LIST_INSERT_HEAD(iax_frames, fr, list);
Tilghman Lesher
committed
ast_free(fr);
static void frame_cache_cleanup(void *data)
{
struct iax_frames *frames = data;
struct iax_frame *cur;
while ((cur = AST_LIST_REMOVE_HEAD(frames, list)))
Tilghman Lesher
committed
ast_free(cur);
Tilghman Lesher
committed
ast_free(frames);
int iax_get_frames(void) { return frames; }
int iax_get_iframes(void) { return iframes; }
int iax_get_oframes(void) { return oframes; }