]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Locking updates for debug mode, fix SIP MWI (bug #2582)
authorMark Spencer <markster@digium.com>
Wed, 6 Oct 2004 04:30:16 +0000 (04:30 +0000)
committerMark Spencer <markster@digium.com>
Wed, 6 Oct 2004 04:30:16 +0000 (04:30 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@3918 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_sip.c
include/asterisk/lock.h

index 3b65a3d7fb52d259a37eaa55ffaa446d842d9f9f..75f9c604248bdd4bb8863fe56779ebb808961891 100755 (executable)
@@ -3943,8 +3943,8 @@ static int transmit_notify_with_mwi(struct sip_pvt *p, int newmsgs, int oldmsgs)
        add_header(&req, "Event", "message-summary");
        add_header(&req, "Content-Type", notifymime);
 
-       snprintf(tmp, sizeof(tmp), "Messages-Waiting: %s\n", newmsgs ? "yes" : "no");
-       snprintf(tmp2, sizeof(tmp2), "Voicemail: %d/%d\n", newmsgs, oldmsgs);
+       snprintf(tmp, sizeof(tmp), "Messages-Waiting: %s\r\n", newmsgs ? "yes" : "no");
+       snprintf(tmp2, sizeof(tmp2), "Voicemail: %d/%d\r\n", newmsgs, oldmsgs);
        snprintf(clen, sizeof(clen), "%d", (int)(strlen(tmp) + strlen(tmp2)));
        add_header(&req, "Content-Length", clen);
        add_line(&req, tmp);
index 059bc89c6cd8d82e612e82977510a1206553ce91..7d2807d8589a45e81d01da57d6d8115e64ba5f31 100755 (executable)
@@ -3,9 +3,9 @@
  *
  * General Asterisk channel definitions.
  * 
- * Copyright (C) 1999, Mark Spencer
+ * Copyright (C) 1999-2004, Digium, Inc.
  *
- * Mark Spencer <markster@linux-support.net>
+ * Mark Spencer <markster@digium.com>
  *
  * This program is free software, distributed under the terms of
  * the GNU General Public License
@@ -65,6 +65,7 @@ struct ast_mutex_info {
        pthread_mutex_t mutex;
        char *file;
        int lineno;
+       int reentrancy;
        char *func;
        pthread_t thread;
 };
@@ -91,6 +92,7 @@ static inline int __ast_pthread_mutex_init_attr(char *filename, int lineno, char
        t->lineno = lineno;
        t->func = func;
        t->thread  = 0;
+       t->reentrancy = 0;
        return pthread_mutex_init(&t->mutex, attr);
 }
 
@@ -210,6 +212,7 @@ static inline int __ast_pthread_mutex_lock(char *filename, int lineno, char *fun
        res = pthread_mutex_lock(&t->mutex);
 #endif /*  DETECT_DEADLOCKS */
        if (!res) {
+               t->reentrancy++;
                t->file = filename;
                t->lineno = lineno;
                t->func = func;
@@ -241,6 +244,7 @@ static inline int __ast_pthread_mutex_trylock(char *filename, int lineno, char *
 #endif /* definded(AST_MUTEX_INIT_W_CONSTRUCTORS) || defined(AST_MUTEX_INIT_ON_FIRST_USE) */
        res = pthread_mutex_trylock(&t->mutex);
        if (!res) {
+               t->reentrancy++;
                t->file = filename;
                t->lineno = lineno;
                t->func = func;
@@ -260,11 +264,18 @@ static inline int __ast_pthread_mutex_unlock(char *filename, int lineno, char *f
                        filename, lineno, func, mutex_name);
        }
 #endif
-       /* Assumes lock is actually held */
-       t->file = NULL;
-       t->lineno = 0;
-       t->func = NULL;
-       t->thread = 0;
+       --t->reentrancy;
+       if (t->reentrancy < 0) {
+               fprintf(stderr, "%s line %d (%s): Freed more times than we've locked!\n",
+                       filename, lineno, func, mutex_name);
+               t->reentrancy = 0;
+       }
+       if (!t->rentrancy) {
+               t->file = NULL;
+               t->lineno = 0;
+               t->func = NULL;
+               t->thread = 0;
+       }
        res = pthread_mutex_unlock(&t->mutex);
        if (res) {
                fprintf(stderr, "%s line %d (%s): Error releasing mutex: %s\n",