Changeset 671 for pjproject/trunk
- Timestamp:
- Aug 10, 2006 9:44:26 PM (18 years ago)
- Location:
- pjproject/trunk/pjsip
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/include/pjsip/sip_dialog.h
r622 r671 109 109 char obj_name[PJ_MAX_OBJ_NAME]; /**< Standard id. */ 110 110 pj_pool_t *pool; /**< Dialog's pool. */ 111 pj_mutex_t *mutex ; /**< Dialog's mutex. Do not call!!111 pj_mutex_t *mutex_; /**< Dialog's mutex. Do not call!! 112 112 Use pjsip_dlg_inc_lock() instead! */ 113 113 pjsip_user_agent *ua; /**< User agent instance. */ -
pjproject/trunk/pjsip/include/pjsip/sip_ua_layer.h
r515 r671 80 80 PJ_DECL(pjsip_user_agent*) pjsip_ua_instance(void); 81 81 82 83 /** 84 * Lock the dialog's hash table. This function is normally called by 85 * dialog code only. 86 * 87 * @return PJ_SUCCESS on success or the appropriate error code. 88 */ 89 PJ_DECL(pj_status_t) pjsip_ua_lock_dlg_table(void); 90 91 92 /** 93 * Unlock the dialog's hash table. This function is normally called by 94 * dialog code only. 95 * 96 * @return PJ_SUCCESS on success or the appropriate error code. 97 */ 98 PJ_DECL(pj_status_t) pjsip_ua_unlock_dlg_table(void); 99 100 82 101 /** 83 102 * Destroy the user agent layer. -
pjproject/trunk/pjsip/src/pjsip-simple/evsub.c
r612 r671 669 669 670 670 671 /* Must lock dialog before using pool etc. */ 672 pjsip_dlg_inc_lock(dlg); 673 671 674 /* Init attributes: */ 672 675 … … 715 718 716 719 status = pjsip_dlg_add_usage(dlg, &mod_evsub.mod, dlgsub_head); 717 if (status != PJ_SUCCESS) 720 if (status != PJ_SUCCESS) { 721 pjsip_dlg_dec_lock(dlg); 718 722 return status; 723 } 719 724 720 725 … … 724 729 725 730 *p_evsub = sub; 731 pjsip_dlg_dec_lock(dlg); 726 732 727 733 return PJ_SUCCESS; -
pjproject/trunk/pjsip/src/pjsip-ua/sip_inv.c
r657 r671 436 436 PJ_ASSERT_RETURN(dlg && p_inv, PJ_EINVAL); 437 437 438 /* Must lock dialog first */ 439 pjsip_dlg_inc_lock(dlg); 440 438 441 /* Normalize options */ 439 442 if (options & PJSIP_INV_REQUIRE_100REL) … … 445 448 /* Create the session */ 446 449 inv = pj_pool_zalloc(dlg->pool, sizeof(pjsip_inv_session)); 447 PJ_ASSERT_RETURN(inv != NULL, PJ_ENOMEM);450 pj_assert(inv != NULL); 448 451 449 452 inv->pool = dlg->pool; … … 462 465 status = pjmedia_sdp_neg_create_w_local_offer(dlg->pool, local_sdp, 463 466 &inv->neg); 464 if (status != PJ_SUCCESS) 467 if (status != PJ_SUCCESS) { 468 pjsip_dlg_dec_lock(dlg); 465 469 return status; 470 } 466 471 } 467 472 468 473 /* Register invite as dialog usage. */ 469 474 status = pjsip_dlg_add_usage(dlg, &mod_inv.mod, inv); 470 if (status != PJ_SUCCESS) 475 if (status != PJ_SUCCESS) { 476 pjsip_dlg_dec_lock(dlg); 471 477 return status; 478 } 472 479 473 480 /* Increment dialog session */ … … 476 483 /* Done */ 477 484 *p_inv = inv; 485 486 pjsip_dlg_dec_lock(dlg); 478 487 479 488 PJ_LOG(5,(inv->obj_name, "UAC invite session created for dialog %s", … … 841 850 PJ_EINVALIDOP); 842 851 852 /* Lock dialog */ 853 pjsip_dlg_inc_lock(dlg); 854 843 855 /* Normalize options */ 844 856 if (options & PJSIP_INV_REQUIRE_100REL) … … 850 862 /* Create the session */ 851 863 inv = pj_pool_zalloc(dlg->pool, sizeof(pjsip_inv_session)); 852 PJ_ASSERT_RETURN(inv != NULL, PJ_ENOMEM);864 pj_assert(inv != NULL); 853 865 854 866 inv->pool = dlg->pool; … … 873 885 status = pjmedia_sdp_validate(rem_sdp); 874 886 875 if (status != PJ_SUCCESS) 887 if (status != PJ_SUCCESS) { 888 pjsip_dlg_dec_lock(dlg); 876 889 return status; 890 } 877 891 } 878 892 … … 889 903 } 890 904 891 if (status != PJ_SUCCESS) 905 if (status != PJ_SUCCESS) { 906 pjsip_dlg_dec_lock(dlg); 892 907 return status; 908 } 893 909 894 910 /* Register invite as dialog usage. */ 895 911 status = pjsip_dlg_add_usage(dlg, &mod_inv.mod, inv); 896 if (status != PJ_SUCCESS) 912 if (status != PJ_SUCCESS) { 913 pjsip_dlg_dec_lock(dlg); 897 914 return status; 915 } 898 916 899 917 /* Increment session in the dialog. */ … … 910 928 911 929 /* Done */ 930 pjsip_dlg_dec_lock(dlg); 912 931 *p_inv = inv; 913 932 -
pjproject/trunk/pjsip/src/pjsip/sip_dialog.c
r635 r671 81 81 pj_list_init(&dlg->inv_hdr); 82 82 83 status = pj_mutex_create_recursive(pool, "dlg%p", &dlg->mutex );83 status = pj_mutex_create_recursive(pool, "dlg%p", &dlg->mutex_); 84 84 if (status != PJ_SUCCESS) 85 85 goto on_error; … … 90 90 91 91 on_error: 92 if (dlg->mutex )93 pj_mutex_destroy(dlg->mutex );92 if (dlg->mutex_) 93 pj_mutex_destroy(dlg->mutex_); 94 94 pjsip_endpt_release_pool(endpt, pool); 95 95 return status; … … 98 98 static void destroy_dialog( pjsip_dialog *dlg ) 99 99 { 100 if (dlg->mutex) 101 pj_mutex_destroy(dlg->mutex); 100 if (dlg->mutex_) { 101 pj_mutex_destroy(dlg->mutex_); 102 dlg->mutex_ = NULL; 103 } 102 104 pjsip_endpt_release_pool(dlg->endpt, dlg->pool); 103 105 } … … 607 609 608 610 /* Destroy this dialog. */ 609 pj_mutex_destroy(dlg->mutex); 610 pjsip_endpt_release_pool(dlg->endpt, dlg->pool); 611 destroy_dialog(dlg); 611 612 612 613 return PJ_SUCCESS; … … 639 640 PJ_ASSERT_RETURN(dlg, PJ_EINVAL); 640 641 641 pj _mutex_lock(dlg->mutex);642 pjsip_dlg_inc_lock(dlg); 642 643 643 644 /* Clear route set. */ … … 645 646 646 647 if (!route_set) { 647 pj _mutex_unlock(dlg->mutex);648 pjsip_dlg_dec_lock(dlg); 648 649 return PJ_SUCCESS; 649 650 } … … 659 660 } 660 661 661 pj_mutex_unlock(dlg->mutex); 662 662 pjsip_dlg_dec_lock(dlg); 663 663 return PJ_SUCCESS; 664 664 } … … 673 673 PJ_ASSERT_RETURN(dlg && mod, PJ_EINVAL); 674 674 675 pj _mutex_lock(dlg->mutex);675 pjsip_dlg_inc_lock(dlg); 676 676 ++dlg->sess_count; 677 pj _mutex_unlock(dlg->mutex);677 pjsip_dlg_dec_lock(dlg); 678 678 679 679 PJ_LOG(5,(dlg->obj_name, "Session count inc to %d by %.*s", … … 685 685 /* 686 686 * Lock dialog and increment session counter temporarily 687 * to prevent it from being deleted. 687 * to prevent it from being deleted. In addition, it must lock 688 * the user agent's dialog table first, to prevent deadlock. 688 689 */ 689 690 PJ_DEF(void) pjsip_dlg_inc_lock(pjsip_dialog *dlg) 690 691 { 691 pj_mutex_lock(dlg->mutex); 692 pjsip_ua_lock_dlg_table(); 693 694 pj_mutex_lock(dlg->mutex_); 692 695 dlg->sess_count++; 696 697 pjsip_ua_unlock_dlg_table(); 693 698 } 694 699 … … 700 705 PJ_DEF(void) pjsip_dlg_dec_lock(pjsip_dialog *dlg) 701 706 { 707 pjsip_ua_lock_dlg_table(); 708 702 709 pj_assert(dlg->sess_count > 0); 703 710 --dlg->sess_count; 704 711 705 712 if (dlg->sess_count==0 && dlg->tsx_count==0) { 706 pj_mutex_unlock(dlg->mutex );707 pj_mutex_lock(dlg->mutex );713 pj_mutex_unlock(dlg->mutex_); 714 pj_mutex_lock(dlg->mutex_); 708 715 unregister_and_destroy_dialog(dlg); 709 716 } else { 710 pj_mutex_unlock(dlg->mutex); 711 } 717 pj_mutex_unlock(dlg->mutex_); 718 } 719 720 pjsip_ua_unlock_dlg_table(); 712 721 } 713 722 … … 725 734 dlg->sess_count-1, (int)mod->name.slen, mod->name.ptr)); 726 735 727 pj_mutex_lock(dlg->mutex); 736 pjsip_dlg_inc_lock(dlg); 737 --dlg->sess_count; 728 738 pjsip_dlg_dec_lock(dlg); 729 739 … … 749 759 (int)mod->name.slen, mod->name.ptr, mod_data)); 750 760 751 pj _mutex_lock(dlg->mutex);761 pjsip_dlg_inc_lock(dlg); 752 762 753 763 /* Usages are sorted on priority, lowest number first. … … 758 768 if (dlg->usage[index] == mod) { 759 769 pj_assert(!"This module is already registered"); 760 pj _mutex_unlock(dlg->mutex);770 pjsip_dlg_dec_lock(dlg); 761 771 return PJSIP_ETYPEEXISTS; 762 772 } … … 778 788 ++dlg->usage_cnt; 779 789 780 pj _mutex_unlock(dlg->mutex);790 pjsip_dlg_dec_lock(dlg); 781 791 782 792 return PJ_SUCCESS; … … 897 907 898 908 /* Lock dialog. */ 899 pj _mutex_lock(dlg->mutex);909 pjsip_dlg_inc_lock(dlg); 900 910 901 911 /* Use outgoing CSeq and increment it by one. */ … … 922 932 923 933 /* Unlock dialog. */ 924 pj _mutex_unlock(dlg->mutex);934 pjsip_dlg_dec_lock(dlg); 925 935 926 936 *p_tdata = tdata; … … 1114 1124 1115 1125 /* Lock the dialog. */ 1116 pj _mutex_lock(dlg->mutex);1126 pjsip_dlg_inc_lock(dlg); 1117 1127 1118 1128 dlg_beautify_response(dlg, st_code, tdata); 1119 1129 1120 1130 /* Unlock the dialog. */ 1121 pj _mutex_unlock(dlg->mutex);1131 pjsip_dlg_dec_lock(dlg); 1122 1132 1123 1133 /* Done. */ -
pjproject/trunk/pjsip/src/pjsip/sip_ua_layer.c
r624 r671 210 210 211 211 212 /** 213 * Lock the dialog's hash table. This function is normally called by 214 * dialog code only. 215 * 216 * @return PJ_SUCCESS on success or the appropriate error code. 217 */ 218 PJ_DEF(pj_status_t) pjsip_ua_lock_dlg_table(void) 219 { 220 return pj_mutex_lock(mod_ua.mutex); 221 } 222 223 224 /** 225 * Unlock the dialog's hash table. This function is normally called by 226 * dialog code only. 227 * 228 * @return PJ_SUCCESS on success or the appropriate error code. 229 */ 230 PJ_DEF(pj_status_t) pjsip_ua_unlock_dlg_table(void) 231 { 232 return pj_mutex_unlock(mod_ua.mutex); 233 } 234 235 212 236 /* 213 237 * Get the endpoint where this UA is currently registered. … … 562 586 rdata->endpt_info.mod_data[mod_ua.mod.id] = dlg; 563 587 588 /* Lock the dialog */ 589 pjsip_dlg_inc_lock(dlg); 590 564 591 /* Done processing in the UA */ 565 592 pj_mutex_unlock(mod_ua.mutex); … … 567 594 /* Pass to dialog. */ 568 595 pjsip_dlg_on_rx_request(dlg, rdata); 596 597 /* Unlock the dialog. This may destroy the dialog */ 598 pjsip_dlg_dec_lock(dlg); 569 599 570 600 /* Report as handled. */ … … 591 621 */ 592 622 623 /* Lock user agent dlg table before we're doing anything. */ 624 pj_mutex_lock(mod_ua.mutex); 625 593 626 /* Check if transaction is present. */ 594 627 tsx = pjsip_rdata_get_tsx(rdata); … … 596 629 /* Check if dialog is present in the transaction. */ 597 630 dlg = pjsip_tsx_get_dlg(tsx); 598 if (!dlg) 631 if (!dlg) { 632 /* Unlock dialog hash table. */ 633 pj_mutex_unlock(mod_ua.mutex); 599 634 return PJ_FALSE; 635 } 600 636 601 637 /* Get the dialog set. */ … … 621 657 * or a very late response. 622 658 */ 659 /* Unlock dialog hash table. */ 660 pj_mutex_unlock(mod_ua.mutex); 623 661 return PJ_FALSE; 624 662 } 625 663 626 /* Lock user agent before accessing the hash table. */627 pj_mutex_lock(mod_ua.mutex);628 664 629 665 /* Get the dialog set. */ … … 633 669 NULL); 634 670 635 /* Done with accessing the hash table. */636 pj_mutex_unlock(mod_ua.mutex);637 638 671 if (!dlg_set) { 672 /* Unlock dialog hash table. */ 673 pj_mutex_unlock(mod_ua.mutex); 674 639 675 /* Strayed 2xx response!! */ 640 676 PJ_LOG(4,(THIS_FILE, … … 666 702 int st_code = rdata->msg_info.msg->line.status.code; 667 703 pj_str_t *to_tag = &rdata->msg_info.to->tag; 668 669 /* Must hold UA mutex before accessing dialog set. */670 pj_mutex_lock(mod_ua.mutex);671 704 672 705 dlg = dlg_set->dlg_list.next; … … 734 767 } 735 768 736 /* Done with the dialog set. */737 pj_mutex_unlock(mod_ua.mutex);738 739 769 } else { 740 770 /* Either this is a non-INVITE response, or subsequent INVITE … … 752 782 rdata->endpt_info.mod_data[mod_ua.mod.id] = dlg; 753 783 784 /* Acquire lock to the dialog. */ 785 pjsip_dlg_inc_lock(dlg); 786 787 /* Unlock dialog hash table. */ 788 pj_mutex_unlock(mod_ua.mutex); 789 754 790 /* Pass the response to the dialog. */ 755 791 pjsip_dlg_on_rx_response(dlg, rdata); 792 793 /* Unlock the dialog. This may destroy the dialog. */ 794 pjsip_dlg_dec_lock(dlg); 756 795 757 796 /* Done. */
Note: See TracChangeset
for help on using the changeset viewer.