aboutsummaryrefslogtreecommitdiffstats
path: root/main/slinfactory.c
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2006-08-29 20:50:36 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2006-08-29 20:50:36 +0000
commit53f8d43e2945038fe3059fd6c1c00dd4ec117505 (patch)
tree0f3fc04bcb07ac328d54ffb2fed0333dfffb44de /main/slinfactory.c
parent562decf81af443d24afd3f1fc3d133b8b2b7cee3 (diff)
Merge team/russell/frame_caching
There are some situations in Asterisk where ast_frame and/or iax_frame structures are rapidly allocatted and freed (at least 50 times per second for one call). This code significantly improves the performance of ast_frame_header_new(), ast_frdup(), ast_frfree(), iax_frame_new(), and iax_frame_free() by keeping a thread-local cache of these structures and using frames from the cache whenever possible instead of calling malloc/free every time. This commit also converts the ast_frame and iax_frame structures to use the linked list macros. git-svn-id: http://svn.digium.com/svn/asterisk/trunk@41278 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/slinfactory.c')
-rw-r--r--main/slinfactory.c17
1 files changed, 5 insertions, 12 deletions
diff --git a/main/slinfactory.c b/main/slinfactory.c
index 62a863d87..0520dbcef 100644
--- a/main/slinfactory.c
+++ b/main/slinfactory.c
@@ -39,7 +39,6 @@ void ast_slinfactory_init(struct ast_slinfactory *sf)
{
memset(sf, 0, sizeof(*sf));
sf->offset = sf->hold;
- sf->queue = NULL;
}
void ast_slinfactory_destroy(struct ast_slinfactory *sf)
@@ -51,10 +50,8 @@ void ast_slinfactory_destroy(struct ast_slinfactory *sf)
sf->trans = NULL;
}
- while ((f = sf->queue)) {
- sf->queue = f->next;
+ while ((f = AST_LIST_REMOVE_HEAD(&sf->queue, frame_list)))
ast_frfree(f);
- }
}
int ast_slinfactory_feed(struct ast_slinfactory *sf, struct ast_frame *f)
@@ -85,15 +82,12 @@ int ast_slinfactory_feed(struct ast_slinfactory *sf, struct ast_frame *f)
if (!frame)
return 0;
- for (x = 0, frame_ptr = sf->queue; frame_ptr && frame_ptr->next; frame_ptr = frame_ptr->next)
+ x = 0;
+ AST_LIST_TRAVERSE(&sf->queue, frame_ptr, frame_list)
x++;
- if (frame_ptr)
- frame_ptr->next = frame;
- else
- sf->queue = frame;
+ AST_LIST_INSERT_TAIL(&sf->queue, frame, frame_list);
- frame->next = NULL;
sf->size += frame->samples;
return x;
@@ -125,8 +119,7 @@ int ast_slinfactory_read(struct ast_slinfactory *sf, short *buf, size_t samples)
continue;
}
- if ((frame_ptr = sf->queue)) {
- sf->queue = frame_ptr->next;
+ if ((frame_ptr = AST_LIST_REMOVE_HEAD(&sf->queue, frame_list))) {
frame_data = frame_ptr->data;
if ((sofar + frame_ptr->samples) <= ineed) {