Merged revisions 38546-38547 via svnmerge from
authorRussell Bryant <russell@russellbryant.com>
Mon, 31 Jul 2006 04:10:43 +0000 (04:10 +0000)
committerRussell Bryant <russell@russellbryant.com>
Mon, 31 Jul 2006 04:10:43 +0000 (04:10 +0000)
https://origsvn.digium.com/svn/asterisk/branches/1.2

........
r38546 | russell | 2006-07-31 00:04:02 -0400 (Mon, 31 Jul 2006) | 2 lines

Make the frame counting done with TRACE_FRAMES defined thread-safe

........
r38547 | russell | 2006-07-31 00:06:16 -0400 (Mon, 31 Jul 2006) | 2 lines

one more small tweak for thread-safety of TRACE_FRAMES

........

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@38548 65c4cc65-6c06-0410-ace0-fbb531ad65f3

frame.c

diff --git a/frame.c b/frame.c
index ac1c72e..4f0cb08 100644 (file)
--- a/frame.c
+++ b/frame.c
@@ -255,9 +255,9 @@ static struct ast_frame *ast_frame_header_new(void)
        struct ast_frame *f = ast_calloc(1, sizeof(*f));
 #ifdef TRACE_FRAMES
        if (f) {
        struct ast_frame *f = ast_calloc(1, sizeof(*f));
 #ifdef TRACE_FRAMES
        if (f) {
-               headers++;
                f->prev = NULL;
                ast_mutex_lock(&framelock);
                f->prev = NULL;
                ast_mutex_lock(&framelock);
+               headers++;
                f->next = headerlist;
                if (headerlist)
                        headerlist->prev = f;
                f->next = headerlist;
                if (headerlist)
                        headerlist->prev = f;
@@ -284,8 +284,8 @@ void ast_frfree(struct ast_frame *fr)
        }
        if (fr->mallocd & AST_MALLOCD_HDR) {
 #ifdef TRACE_FRAMES
        }
        if (fr->mallocd & AST_MALLOCD_HDR) {
 #ifdef TRACE_FRAMES
-               headers--;
                ast_mutex_lock(&framelock);
                ast_mutex_lock(&framelock);
+               headers--;
                if (fr->next)
                        fr->next->prev = fr->prev;
                if (fr->prev)
                if (fr->next)
                        fr->next->prev = fr->prev;
                if (fr->prev)
@@ -860,11 +860,11 @@ static int show_frame_stats(int fd, int argc, char *argv[])
        int x=1;
        if (argc != 3)
                return RESULT_SHOWUSAGE;
        int x=1;
        if (argc != 3)
                return RESULT_SHOWUSAGE;
+       ast_mutex_lock(&framelock);
        ast_cli(fd, "     Framer Statistics     \n");
        ast_cli(fd, "---------------------------\n");
        ast_cli(fd, "Total allocated headers: %d\n", headers);
        ast_cli(fd, "Queue Dump:\n");
        ast_cli(fd, "     Framer Statistics     \n");
        ast_cli(fd, "---------------------------\n");
        ast_cli(fd, "Total allocated headers: %d\n", headers);
        ast_cli(fd, "Queue Dump:\n");
-       ast_mutex_lock(&framelock);
        for (f=headerlist; f; f = f->next) {
                ast_cli(fd, "%d.  Type %d, subclass %d from %s\n", x++, f->frametype, f->subclass, f->src ? f->src : "<Unknown>");
        }
        for (f=headerlist; f; f = f->next) {
                ast_cli(fd, "%d.  Type %d, subclass %d from %s\n", x++, f->frametype, f->subclass, f->src ? f->src : "<Unknown>");
        }