Changeset 5762
- Timestamp:
- Apr 2, 2018 2:53:48 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c
r5755 r5762 1252 1252 pj_time_val timeout = {0, 0}; 1253 1253 1254 if (sess->destroy_flag) 1255 return; 1256 1254 1257 sess->destroy_flag = PJ_TRUE; 1255 1256 /* If the STUN resolution session is blocking, only the waiting thread1257 * is allowed to destroy the session, otherwise it may cause deadlock.1258 */1259 if (sess->blocking) {1260 if (sess->waiter != pj_thread_this())1261 return;1262 1263 /* Before destroying, make sure ref count is zero. */1264 while (sess->ref_cnt > 0)1265 pj_thread_sleep(10);1266 1267 } else if (sess->ref_cnt > 0)1268 return;1269 1270 1258 if (sess->stun_sock) { 1271 1259 pj_stun_sock_destroy(sess->stun_sock); … … 1291 1279 static void stun_resolve_dec_ref(pjsua_stun_resolve *sess) 1292 1280 { 1293 --sess->ref_cnt; 1294 if (sess->ref_cnt <= 0 && sess->destroy_flag) 1295 destroy_stun_resolve(sess); 1281 int ref_cnt = --sess->ref_cnt; 1282 /* If the STUN resolution session is blocking, only the waiting thread 1283 * is allowed to destroy the session, otherwise it may cause deadlock. 1284 */ 1285 if ((ref_cnt > 0) || 1286 (sess->blocking && (sess->waiter != pj_thread_this()))) 1287 { 1288 return; 1289 } 1290 1291 destroy_stun_resolve(sess); 1296 1292 } 1297 1293 … … 1333 1329 on_return: 1334 1330 if (!sess->blocking) { 1335 destroy_stun_resolve(sess);1331 stun_resolve_dec_ref(sess); 1336 1332 } 1337 1333 } … … 1564 1560 sess->status = PJ_EPENDING; 1565 1561 sess->af = pj_AF_INET(); 1562 stun_resolve_add_ref(sess); 1566 1563 sess->srv = (pj_str_t*) pj_pool_calloc(pool, count, sizeof(pj_str_t)); 1567 1564 for (i=0; i<count; ++i) { … … 1584 1581 max_wait_ms = count * pjsua_var.stun_cfg.rto_msec * (1 << 7); 1585 1582 pj_get_timestamp(&start); 1586 1587 while ( sess->status == PJ_EPENDING) {1583 1584 while ((sess->status == PJ_EPENDING) && (!sess->destroy_flag)) { 1588 1585 /* If there is no worker thread or 1589 1586 * the function is called from the only worker thread, … … 1605 1602 1606 1603 status = sess->status; 1607 destroy_stun_resolve(sess);1604 stun_resolve_dec_ref(sess); 1608 1605 1609 1606 return status; … … 1625 1622 1626 1623 if (sess->token == token) { 1624 sess->has_result = PJ_TRUE; 1625 sess->status = PJ_ECANCELLED; 1627 1626 if (notify_cb) { 1628 1627 pj_stun_resolve_result result; … … 1633 1632 1634 1633 sess->cb(&result); 1635 } 1636 1637 destroy_stun_resolve(sess); 1634 } 1638 1635 ++cancelled_count; 1639 1636 }
Note: See TracChangeset
for help on using the changeset viewer.