Hold owner lock when changing codecs
authorMark Spencer <markster@digium.com>
Tue, 23 Mar 2004 00:56:36 +0000 (00:56 +0000)
committerMark Spencer <markster@digium.com>
Tue, 23 Mar 2004 00:56:36 +0000 (00:56 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@2529 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_iax2.c

index 5b17fa4..404f32a 100755 (executable)
@@ -4948,11 +4948,21 @@ retryowner:
                                                iaxs[fr.callno]->owner->nativeformats = iaxs[fr.callno]->peerformat;
                                                if (option_verbose > 2)
                                                        ast_verbose(VERBOSE_PREFIX_3 "Format for call is %s\n", ast_getformatname(iaxs[fr.callno]->owner->nativeformats));
-                                               /* Setup read/write formats properly. */
-                                               if (iaxs[fr.callno]->owner->writeformat)
-                                                       ast_set_write_format(iaxs[fr.callno]->owner, iaxs[fr.callno]->owner->writeformat);      
-                                               if (iaxs[fr.callno]->owner->readformat)
-                                                       ast_set_read_format(iaxs[fr.callno]->owner, iaxs[fr.callno]->owner->readformat);        
+retryowner2:
+                                               if (ast_mutex_trylock(&iaxs[fr.callno]->owner->lock)) {
+                                                       ast_mutex_unlock(&iaxsl[fr.callno]);
+                                                       usleep(1);
+                                                       ast_mutex_lock(&iaxsl[fr.callno]);
+                                                       if (iaxs[fr.callno] && iaxs[fr.callno]->owner) goto retryowner2;
+                                               }
+                                               
+                                               if (iaxs[fr.callno] && iaxs[fr.callno]->owner) {
+                                                       /* Setup read/write formats properly. */
+                                                       if (iaxs[fr.callno]->owner->writeformat)
+                                                               ast_set_write_format(iaxs[fr.callno]->owner, iaxs[fr.callno]->owner->writeformat);      
+                                                       if (iaxs[fr.callno]->owner->readformat)
+                                                               ast_set_read_format(iaxs[fr.callno]->owner, iaxs[fr.callno]->owner->readformat);        
+                                               }
                                        }
                                }
                                ast_mutex_lock(&dpcache_lock);