Changeset 5022
Faster cw_slinfactory_feed() implementation.
cw_slinfactory_feed() used an O(N) list insert. Now it uses O(1), at
the cost of an extra pointer and integer in struct cw_slinfactory.
Committed by:
karvan
Date:
Jul 01 2008 * 20:34 (5 months ago)
Affected files:
callweaver/branches/karvan/corelib/slinfactory.c (diff)
callweaver/branches/karvan/include/callweaver/slinfactory.h (diff)
callweaver/branches/karvan/corelib/slinfactory.c (unified diff)
| r4723 | r5022 | |
|---|---|---|
| 43 | 43 | { |
| 44 | 44 | memset(sf, 0, sizeof(struct cw_slinfactory)); |
| 45 | 45 | sf->offset = sf->hold; |
| 46 | sf->queue = NULL; | |
| 46 | sf->queue.head = sf->queue.tail = NULL; | |
| 47 | 47 | cw_mutex_init(&(sf->lock)); |
| 48 | 48 | } |
| 49 | 49 | |
| --- | --- | |
| 57 | 57 | sf->trans = NULL; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | while ((f = sf->queue)) | |
| 60 | while ((f = sf->queue.head)) | |
| 61 | 61 | { |
| 62 | sf->queue = f->next; | |
| 62 | sf->queue.head = f->next; | |
| 63 | 63 | cw_fr_free(f); |
| 64 | 64 | } |
| 65 | 65 | cw_mutex_destroy(&(sf->lock)); |
| --- | --- | |
| 69 | 69 | int cw_slinfactory_feed(struct cw_slinfactory *sf, struct cw_frame *f) |
| 70 | 70 | { |
| 71 | 71 | struct cw_frame *frame; |
| 72 | struct cw_frame *frame_ptr; | |
| 73 | 72 | |
| 74 | 73 | if (f == NULL) |
| 75 | 74 | return 0; |
| --- | --- | |
| 104 | 103 | } |
| 105 | 104 | if (frame) |
| 106 | 105 | { |
| 107 | int x = 0; | |
| 106 | int x = ++sf->queue.count; | |
| 108 | 107 | |
| 109 | 108 | frame->next = NULL; |
| 110 | 109 | |
| 111 | for (frame_ptr = sf->queue; frame_ptr && frame_ptr->next; frame_ptr=frame_ptr->next) | |
| 112 | x++; | |
| 113 | if (frame_ptr) | |
| 114 | frame_ptr->next = frame; | |
| 115 | else | |
| 116 | sf->queue = frame; | |
| 110 | if (sf->queue.tail) | |
| 111 | sf->queue.tail->next = frame; | |
| 112 | else | |
| 113 | sf->queue.head = frame; | |
| 114 | sf->queue.tail = frame; | |
| 117 | 115 | frame->next = NULL; |
| 118 | 116 | sf->size += frame->datalen; |
| 119 | 117 | cw_mutex_unlock(&(sf->lock)); |
| --- | --- | |
| 161 | 159 | continue; |
| 162 | 160 | } |
| 163 | 161 | |
| 164 | if (sofar >= bytes || (frame_ptr = sf->queue) == NULL) | |
| 162 | if (sofar >= bytes || (frame_ptr = sf->queue.head) == NULL) | |
| 165 | 163 | break; |
| 166 | 164 | |
| 167 | sf->queue = frame_ptr->next; | |
| 165 | sf->queue.head = frame_ptr->next; | |
| 166 | if (NULL == sf->queue.head) | |
| 167 | sf->queue.tail = NULL; | |
| 168 | --sf->queue.count; | |
| 168 | 169 | frame_data = frame_ptr->data; |
| 169 | 170 | |
| 170 | 171 | if (frame_ptr->datalen <= ineed) |
callweaver/branches/karvan/include/callweaver/slinfactory.h (unified diff)
| r4723 | r5022 | |
|---|---|---|
| 35 | 35 | #endif |
| 36 | 36 | |
| 37 | 37 | struct cw_slinfactory { |
| 38 | struct cw_frame *queue; | |
| 38 | struct { | |
| 39 | struct cw_frame *head; | |
| 40 | struct cw_frame *tail; | |
| 41 | unsigned count; | |
| 42 | } queue; | |
| 39 | 43 | struct cw_trans_pvt *trans; |
| 40 | 44 | short hold[1280]; |
| 41 | 45 | short *offset; |
![Home changeset 5022 [home]](/images/logo.png?1180520111)
RSS Feeds