Changeset 5826
- Timestamp:
- Jul 17, 2018 10:49:57 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib-util/src/pjlib-util/resolver.c
r5612 r5826 170 170 /* Internals */ 171 171 pj_pool_t *pool; /**< Internal pool. */ 172 pj_ mutex_t *mutex; /**< Mutex protection.*/172 pj_grp_lock_t *grp_lock; /**< Group lock protection. */ 173 173 pj_bool_t own_timer; /**< Do we own timer? */ 174 174 pj_timer_heap_t *timer; /**< Timer instance. */ … … 237 237 unsigned servers[]); 238 238 239 /* Destructor */ 240 static void dns_resolver_on_destroy(void *member); 239 241 240 242 /* Close UDP socket */ … … 285 287 pj_bzero(&socket_cb, sizeof(socket_cb)); 286 288 socket_cb.on_read_complete = &on_read_complete; 287 status = pj_ioqueue_register_sock (resv->pool, resv->ioqueue,288 resv->udp_sock, resv, &socket_cb,289 &resv->udp_key);289 status = pj_ioqueue_register_sock2(resv->pool, resv->ioqueue, 290 resv->udp_sock, resv->grp_lock, 291 resv, &socket_cb, &resv->udp_key); 290 292 if (status != PJ_SUCCESS) 291 293 return status; … … 332 334 pj_bzero(&socket_cb, sizeof(socket_cb)); 333 335 socket_cb.on_read_complete = &on_read_complete; 334 status = pj_ioqueue_register_sock (resv->pool, resv->ioqueue,335 resv->udp6_sock, resv, &socket_cb,336 &resv->udp6_key);336 status = pj_ioqueue_register_sock2(resv->pool, resv->ioqueue, 337 resv->udp6_sock, resv->grp_lock, 338 resv, &socket_cb, &resv->udp6_key); 337 339 if (status != PJ_SUCCESS) 338 340 return status; … … 403 405 pj_strdup2_with_null(pool, &resv->name, name); 404 406 405 /* Create the mutex */ 406 status = pj_mutex_create_recursive(pool, name, &resv->mutex); 407 /* Create group lock */ 408 status = pj_grp_lock_create_w_handler(pool, NULL, resv, 409 &dns_resolver_on_destroy, 410 &resv->grp_lock); 407 411 if (status != PJ_SUCCESS) 408 412 goto on_error; 413 414 pj_grp_lock_add_ref(resv->grp_lock); 409 415 410 416 /* Timer, ioqueue, and settings */ … … 418 424 /* Create the timer heap if one is not specified */ 419 425 if (resv->timer == NULL) { 426 resv->own_timer = PJ_TRUE; 420 427 status = pj_timer_heap_create(pool, TIMER_SIZE, &resv->timer); 421 428 if (status != PJ_SUCCESS) … … 425 432 /* Create the ioqueue if one is not specified */ 426 433 if (resv->ioqueue == NULL) { 434 resv->own_ioqueue = PJ_TRUE; 427 435 status = pj_ioqueue_create(pool, MAX_FD, &resv->ioqueue); 428 436 if (status != PJ_SUCCESS) … … 450 458 pj_dns_resolver_destroy(resv, PJ_FALSE); 451 459 return status; 460 } 461 462 463 void dns_resolver_on_destroy(void *member) 464 { 465 pj_dns_resolver *resolver = (pj_dns_resolver*)member; 466 pj_pool_safe_release(&resolver->pool); 452 467 } 453 468 … … 509 524 } 510 525 511 if (resolver->mutex) { 512 pj_mutex_destroy(resolver->mutex); 513 resolver->mutex = NULL; 514 } 515 516 pj_pool_safe_release(&resolver->pool); 526 pj_grp_lock_dec_ref(resolver->grp_lock); 517 527 518 528 return PJ_SUCCESS; … … 536 546 PJ_ASSERT_RETURN(count < PJ_DNS_RESOLVER_MAX_NS, PJ_EINVAL); 537 547 538 pj_ mutex_lock(resolver->mutex);548 pj_grp_lock_acquire(resolver->grp_lock); 539 549 540 550 if (count > PJ_DNS_RESOLVER_MAX_NS) … … 555 565 (pj_uint16_t)(ports ? ports[i] : PORT)); 556 566 if (status != PJ_SUCCESS) { 557 pj_ mutex_unlock(resolver->mutex);567 pj_grp_lock_release(resolver->grp_lock); 558 568 return PJLIB_UTIL_EDNSINNSADDR; 559 569 } … … 566 576 resolver->ns_count = count; 567 577 568 pj_ mutex_unlock(resolver->mutex);578 pj_grp_lock_release(resolver->grp_lock); 569 579 return PJ_SUCCESS; 570 580 } … … 580 590 PJ_ASSERT_RETURN(resolver && st, PJ_EINVAL); 581 591 582 pj_ mutex_lock(resolver->mutex);592 pj_grp_lock_acquire(resolver->grp_lock); 583 593 pj_memcpy(&resolver->settings, st, sizeof(*st)); 584 pj_ mutex_unlock(resolver->mutex);594 pj_grp_lock_release(resolver->grp_lock); 585 595 return PJ_SUCCESS; 586 596 } … … 595 605 PJ_ASSERT_RETURN(resolver && st, PJ_EINVAL); 596 606 597 pj_ mutex_lock(resolver->mutex);607 pj_grp_lock_acquire(resolver->grp_lock); 598 608 pj_memcpy(st, &resolver->settings, sizeof(*st)); 599 pj_ mutex_unlock(resolver->mutex);609 pj_grp_lock_release(resolver->grp_lock); 600 610 return PJ_SUCCESS; 601 611 } … … 610 620 PJ_ASSERT_ON_FAIL(resolver, return); 611 621 612 pj_ mutex_lock(resolver->mutex);622 pj_grp_lock_acquire(resolver->grp_lock); 613 623 pj_timer_heap_poll(resolver->timer, NULL); 614 pj_ mutex_unlock(resolver->mutex);624 pj_grp_lock_release(resolver->grp_lock); 615 625 616 626 pj_ioqueue_poll(resolver->ioqueue, timeout); … … 684 694 delay.msec = resolver->settings.qretr_delay; 685 695 pj_time_val_normalize(&delay); 686 status = pj_timer_heap_schedule(resolver->timer, &q->timer_entry, &delay); 696 status = pj_timer_heap_schedule_w_grp_lock(resolver->timer, 697 &q->timer_entry, 698 &delay, 1, 699 resolver->grp_lock); 687 700 if (status != PJ_SUCCESS) { 688 701 return status; … … 874 887 875 888 /* Start working with the resolver */ 876 pj_ mutex_lock(resolver->mutex);889 pj_grp_lock_acquire(resolver->grp_lock); 877 890 878 891 /* Get current time. */ … … 907 920 */ 908 921 cache->ref_cnt++; 909 pj_ mutex_unlock(resolver->mutex);922 pj_grp_lock_release(resolver->grp_lock); 910 923 911 924 /* This cached response is still valid. Just return this … … 917 930 918 931 /* Done. No host resolution is necessary */ 919 pj_ mutex_lock(resolver->mutex);932 pj_grp_lock_acquire(resolver->grp_lock); 920 933 921 934 /* Decrement the ref counter. Also check if it is time to free … … 934 947 * Refer to ticket #1974. 935 948 */ 936 pj_ mutex_unlock(resolver->mutex);949 pj_grp_lock_release(resolver->grp_lock); 937 950 return status; 938 951 } … … 1001 1014 *p_query = p_q; 1002 1015 1003 pj_ mutex_unlock(resolver->mutex);1016 pj_grp_lock_release(resolver->grp_lock); 1004 1017 return status; 1005 1018 } … … 1016 1029 PJ_ASSERT_RETURN(query, PJ_EINVAL); 1017 1030 1018 pj_mutex_lock(query->resolver->mutex); 1031 pj_grp_lock_acquire(query->resolver->grp_lock); 1032 1033 if (query->timer_entry.id == 1) { 1034 pj_timer_heap_cancel_if_active(query->resolver->timer, 1035 &query->timer_entry, 0); 1036 } 1019 1037 1020 1038 cb = query->cb; … … 1024 1042 (*cb)(query->user_data, PJ_ECANCELLED, NULL); 1025 1043 1026 pj_ mutex_unlock(query->resolver->mutex);1044 pj_grp_lock_release(query->resolver->grp_lock); 1027 1045 return PJ_SUCCESS; 1028 1046 } … … 1553 1571 resolver = q->resolver; 1554 1572 1555 pj_ mutex_lock(resolver->mutex);1573 pj_grp_lock_acquire(resolver->grp_lock); 1556 1574 1557 1575 /* Recheck that this query is still pending, since there is a slight … … 1561 1579 if (pj_hash_get(resolver->hquerybyid, &q->id, sizeof(q->id), NULL)==NULL) { 1562 1580 /* Yeah, this query is done. */ 1563 pj_ mutex_unlock(resolver->mutex);1581 pj_grp_lock_release(resolver->grp_lock); 1564 1582 return; 1565 1583 } … … 1572 1590 status = transmit_query(resolver, q); 1573 1591 if (status == PJ_SUCCESS) { 1574 pj_ mutex_unlock(resolver->mutex);1592 pj_grp_lock_release(resolver->grp_lock); 1575 1593 return; 1576 1594 } else { … … 1591 1609 1592 1610 /* Workaround for deadlock problem in #1565 (similar to #1108) */ 1593 pj_ mutex_unlock(resolver->mutex);1611 pj_grp_lock_release(resolver->grp_lock); 1594 1612 1595 1613 /* Call application callback, if any. */ … … 1606 1624 1607 1625 /* Workaround for deadlock problem in #1565 (similar to #1108) */ 1608 pj_ mutex_lock(resolver->mutex);1626 pj_grp_lock_acquire(resolver->grp_lock); 1609 1627 1610 1628 /* Clear data */ … … 1623 1641 pj_list_push_back(&resolver->query_free_nodes, q); 1624 1642 1625 pj_ mutex_unlock(resolver->mutex);1643 pj_grp_lock_release(resolver->grp_lock); 1626 1644 } 1627 1645 … … 1663 1681 } 1664 1682 1665 pj_ mutex_lock(resolver->mutex);1683 pj_grp_lock_acquire(resolver->grp_lock); 1666 1684 1667 1685 … … 1746 1764 1747 1765 /* Workaround for deadlock problem in #1108 */ 1748 pj_ mutex_unlock(resolver->mutex);1766 pj_grp_lock_release(resolver->grp_lock); 1749 1767 1750 1768 /* Notify applications first, to allow application to modify the … … 1767 1785 1768 1786 /* Workaround for deadlock problem in #1108 */ 1769 pj_ mutex_lock(resolver->mutex);1787 pj_grp_lock_acquire(resolver->grp_lock); 1770 1788 1771 1789 /* Save/update response cache. */ … … 1796 1814 src_addr, src_addr_len); 1797 1815 1798 if (status != PJ_EPENDING ) {1816 if (status != PJ_EPENDING && status != PJ_ECANCELLED) { 1799 1817 char errmsg[PJ_ERR_MSG_SIZE]; 1800 1818 … … 1806 1824 } 1807 1825 1808 pj_ mutex_unlock(resolver->mutex);1826 pj_grp_lock_release(resolver->grp_lock); 1809 1827 } 1810 1828 … … 1832 1850 PJLIB_UTIL_EDNSNOANSWERREC); 1833 1851 1834 pj_ mutex_lock(resolver->mutex);1852 pj_grp_lock_acquire(resolver->grp_lock); 1835 1853 1836 1854 /* Build resource key for looking up hash tables */ … … 1854 1872 update_res_cache(resolver, &key, PJ_SUCCESS, set_ttl, pkt); 1855 1873 1856 pj_ mutex_unlock(resolver->mutex);1874 pj_grp_lock_release(resolver->grp_lock); 1857 1875 1858 1876 return PJ_SUCCESS; … … 1869 1887 PJ_ASSERT_RETURN(resolver, 0); 1870 1888 1871 pj_ mutex_lock(resolver->mutex);1889 pj_grp_lock_acquire(resolver->grp_lock); 1872 1890 count = pj_hash_count(resolver->hrescache); 1873 pj_ mutex_unlock(resolver->mutex);1891 pj_grp_lock_release(resolver->grp_lock); 1874 1892 1875 1893 return count; … … 1887 1905 pj_time_val now; 1888 1906 1889 pj_ mutex_lock(resolver->mutex);1907 pj_grp_lock_acquire(resolver->grp_lock); 1890 1908 1891 1909 pj_gettimeofday(&now); … … 1947 1965 pj_pool_get_used_size(resolver->pool))); 1948 1966 1949 pj_ mutex_unlock(resolver->mutex);1967 pj_grp_lock_release(resolver->grp_lock); 1950 1968 #endif 1951 1969 }
Note: See TracChangeset
for help on using the changeset viewer.