[Asterisk-cvs] asterisk-addons/asterisk-ooh323c/src chan_h323.c, 1.17, 1.18

vphirke vphirke
Tue Nov 22 11:46:58 CST 2005


Update of /usr/cvsroot/asterisk-addons/asterisk-ooh323c/src
In directory mongoose.digium.com:/tmp/cvs-serv32651/src

Modified Files:
	chan_h323.c 
Log Message:
Fix for channel mutex deadlock condition

Index: chan_h323.c
===================================================================
RCS file: /usr/cvsroot/asterisk-addons/asterisk-ooh323c/src/chan_h323.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- chan_h323.c	11 Nov 2005 20:49:21 -0000	1.17
+++ chan_h323.c	22 Nov 2005 16:36:03 -0000	1.18
@@ -88,7 +88,7 @@
 	.set_rtp_peer=  ooh323_set_rtp_peer
 };
 
-/* H.323 channel specific data */
+/* H.323 channel private structure */
 static struct ooh323_pvt {
    ast_mutex_t lock;		/* Channel private lock */
    struct ast_rtp *rtp;
@@ -127,7 +127,7 @@
    struct ooh323_pvt *next;	/* Next entity */
 } *iflist = NULL;
 
-/* Protect the channel list (of h323_pvt's) */
+/* Protect the channel/interface list (ooh323_pvt) */
 AST_MUTEX_DEFINE_STATIC(iflock);
 
 /* Profile of H.323 user registered with PBX*/
@@ -146,6 +146,7 @@
    struct ooh323_user *next;
 };
 
+/* Profile of valid asterisk peers */
 struct ooh323_peer{
    ast_mutex_t lock;
    char        name[256];
@@ -178,11 +179,11 @@
   ast_mutex_t lock;
 }peerl;
 
+/* Mutex to protect H.323 reload process */
 static int h323_reloading = 0;
 AST_MUTEX_DEFINE_STATIC(h323_reload_lock);
 
-
-
+/* Mutex to protect usage counter */
 static int usecnt =0;
 AST_MUTEX_DEFINE_STATIC(usecnt_lock);
 
@@ -1372,29 +1373,29 @@
    }
    ast_mutex_lock(&p->lock);
   
-retrylock:
-   if(p->owner && ast_mutex_trylock(&p->owner->lock))
-   {
-      ast_log(LOG_DEBUG,"Failed to grab lock, trying again\n");
-      ast_mutex_unlock(&p->lock);
-      usleep(1);
-      ast_mutex_lock(&p->lock);
-      goto retrylock;
-   }    
+   if(p->owner) {
+      while(ast_mutex_trylock(&p->owner->lock))
+      {
+         ast_log(LOG_DEBUG,"Failed to grab lock, trying again\n");
+         ast_mutex_unlock(&p->lock);
+         usleep(1);
+         ast_mutex_lock(&p->lock);
+      }    
+
+      c = p->owner;
 
-   c = p->owner;
-   if (c) {      
       if(!ast_test_flag(p, H323_ALREADYGONE))
       { /* NOTE Channel is not detached yet */
          ast_set_flag(p, H323_ALREADYGONE);
          p->owner->hangupcause = ooh323_convert_hangupcause_h323ToAsterisk(
                                                           call->callEndReason);
          p->owner->_softhangup |= AST_SOFTHANGUP_DEV;
-         ast_queue_hangup(p->owner);
          ast_mutex_unlock(&p->owner->lock);
+         ast_queue_hangup(p->owner);
          ast_mutex_unlock(&p->lock);
          return OO_OK;
       }
+      ast_mutex_unlock(&p->owner->lock);
    }
    ast_set_flag(p, H323_NEEDDESTROY);
    ast_mutex_unlock(&p->lock);
@@ -1402,7 +1403,7 @@
    if(gH323Debug)
       ast_verbose("+++   onCallCleared\n");
 
-  return OO_OK;
+   return OO_OK;
 }
 
 static void ooh323_delete_user(struct ooh323_user *user)
@@ -1672,8 +1673,10 @@
    ast_mutex_lock(&h323_reload_lock);
    if (h323_reloading) {
       ast_verbose("Previous OOH323 reload not yet done\n");
-   } else
+   } 
+   else {
       h323_reloading = 1;
+   }
    ast_mutex_unlock(&h323_reload_lock);
    restart_monitor();
 
@@ -2430,20 +2433,22 @@
       }
       /* Check for interfaces needing to be killed */
       ast_mutex_lock(&iflock);
-restartsearch:		
-      time(&t);
-      h323 = iflist;
-      while(h323) {
-         ast_mutex_lock(&h323->lock);
-      /*TODO: Need to add rtptimeout keepalive support */
-		 
-         if(ast_test_flag(h323, H323_NEEDDESTROY)) {
-			 ooh323_destroy(h323);
-			 ast_mutex_unlock(&h323->lock);
-			 goto restartsearch;
+      int b_restartsearch = 1;
+      while(b_restartsearch) {
+         time(&t);
+         h323 = iflist;
+         while(h323) {
+            ast_mutex_lock(&h323->lock);
+            /*TODO: Need to add rtptimeout keepalive support */
+            if(ast_test_flag(h323, H323_NEEDDESTROY)) {
+               ooh323_destroy(h323);
+               ast_mutex_unlock(&h323->lock);
+               break;
+            }
+            ast_mutex_unlock(&h323->lock);
+            h323 = h323->next;
          }
-         ast_mutex_unlock(&h323->lock);
-		 h323 = h323->next;
+         b_restartsearch = 0;
       }
       ast_mutex_unlock(&iflock);
       pthread_testcancel();
@@ -2483,7 +2488,8 @@
    if (monitor_thread != AST_PTHREADT_NULL) {
       /* Wake up the thread */
       pthread_kill(monitor_thread, SIGURG);
-   } else {
+   } 
+   else {
       pthread_attr_init(&attr);
       pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
       /* Start a new monitor */




More information about the svn-commits mailing list