[asterisk-commits] russell: branch russell/iax2_ff r70855 - /team/russell/iax2_ff/channels/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Jun 21 15:26:16 CDT 2007
Author: russell
Date: Thu Jun 21 15:26:15 2007
New Revision: 70855
URL: http://svn.digium.com/view/asterisk?view=rev&rev=70855
Log:
Ensure that handling of the deferred full frames list is thread safe and also
make sure that it's not possible for a frame to get queued up and never
processed
Modified:
team/russell/iax2_ff/channels/chan_iax2.c
Modified: team/russell/iax2_ff/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/russell/iax2_ff/channels/chan_iax2.c?view=diff&rev=70855&r1=70854&r2=70855
==============================================================================
--- team/russell/iax2_ff/channels/chan_iax2.c (original)
+++ team/russell/iax2_ff/channels/chan_iax2.c Thu Jun 21 15:26:15 2007
@@ -6287,17 +6287,17 @@
static int socket_process(struct iax2_thread *thread);
/*!
- * \brief Check to see if they are deferred full frames for this thread
- *
- * \retval 0 No deferred frames were present
- * \retval non-zero A deferred full frame has been copied into the
- * thread's main buffer for processing
+ * \brief Handle any deferred full frames for this thread
*/
-static int check_deferred_full_frames(struct iax2_thread *thread)
+static void handle_deferred_full_frames(struct iax2_thread *thread)
{
struct iax2_pkt_buf *pkt_buf;
+ ast_mutex_lock(&thread->lock);
+
while ((pkt_buf = AST_LIST_REMOVE_HEAD(&thread->full_frames, entry))) {
+ ast_mutex_unlock(&thread->lock);
+
thread->buf = pkt_buf->buf;
thread->buf_len = pkt_buf->len;
thread->buf_size = pkt_buf->len + 1;
@@ -6305,11 +6305,12 @@
socket_process(thread);
thread->buf = NULL;
-
ast_free(pkt_buf);
- }
-
- return 1;
+
+ ast_mutex_lock(&thread->lock);
+ }
+
+ ast_mutex_unlock(&thread->lock);
}
/*!
@@ -6330,6 +6331,7 @@
memcpy(pkt_buf->buf, thread->buf, pkt_buf->len);
fh = (struct ast_iax2_full_hdr *) pkt_buf->buf;
+ ast_mutex_lock(&thread->lock);
AST_LIST_TRAVERSE_SAFE_BEGIN(&thread->full_frames, cur_pkt_buf, entry) {
cur_fh = (struct ast_iax2_full_hdr *) cur_pkt_buf->buf;
if (fh->oseqno < cur_fh->oseqno) {
@@ -6341,6 +6343,8 @@
if (!cur_pkt_buf)
AST_LIST_INSERT_TAIL(&thread->full_frames, pkt_buf, entry);
+
+ ast_mutex_unlock(&thread->lock);
}
static int socket_read(int *id, int fd, short events, void *cbdata)
@@ -6390,11 +6394,11 @@
!inaddrcmp(&cur->ffinfo.sin, &thread->iosin))
break;
}
- AST_LIST_UNLOCK(&active_list);
if (cur) {
/* we found another thread processing a full frame for this call,
so queue it up for processing later. */
defer_full_frame(thread);
+ AST_LIST_UNLOCK(&active_list);
return 1;
} else {
/* this thread is going to process this frame, so mark it */
@@ -6403,6 +6407,7 @@
thread->ffinfo.type = fh->type;
thread->ffinfo.csub = fh->csub;
}
+ AST_LIST_UNLOCK(&active_list);
}
/* Mark as ready and send on its way */
@@ -7875,7 +7880,7 @@
thread->actions++;
thread->iostate = IAX_IOSTATE_PROCESSING;
socket_process(thread);
- check_deferred_full_frames(thread);
+ handle_deferred_full_frames(thread);
break;
case IAX_IOSTATE_SCHEDREADY:
thread->actions++;
@@ -7895,6 +7900,9 @@
AST_LIST_LOCK(&active_list);
AST_LIST_REMOVE(&active_list, thread, list);
AST_LIST_UNLOCK(&active_list);
+
+ /* Make sure another frame didn't sneak in there after we thought we were done. */
+ handle_deferred_full_frames(thread);
/* Go back into our respective list */
put_into_idle = 1;
More information about the asterisk-commits
mailing list