Changeset 4552
- Timestamp:
- Jul 5, 2013 8:14:14 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib-util/src/pjlib-util/resolver.c
r4537 r4552 158 158 pj_time_val expiry_time; /**< Expiration time. */ 159 159 pj_dns_parsed_packet *pkt; /**< The response packet. */ 160 unsigned ref_cnt; /**< Reference counter. */ 160 161 }; 161 162 … … 701 702 cache = PJ_POOL_ZALLOC_T(pool, struct cached_res); 702 703 cache->pool = pool; 704 cache->ref_cnt = 1; 703 705 704 706 return cache; 707 } 708 709 /* Re-allocate cache entry, to free cached packet */ 710 static void reset_entry(struct cached_res **p_cached) 711 { 712 pj_pool_t *pool; 713 struct cached_res *cache = *p_cached; 714 unsigned ref_cnt; 715 716 pool = cache->pool; 717 ref_cnt = cache->ref_cnt; 718 719 pj_pool_reset(pool); 720 721 cache = PJ_POOL_ZALLOC_T(pool, struct cached_res); 722 cache->pool = pool; 723 cache->ref_cnt = ref_cnt; 724 *p_cached = cache; 705 725 } 706 726 … … 776 796 status = PJ_STATUS_FROM_DNS_RCODE(status); 777 797 798 /* Workaround for deadlock problem. Need to increment the cache's 799 * ref counter first before releasing mutex, so the cache won't be 800 * destroyed by other thread while in callback. 801 */ 802 cache->ref_cnt++; 803 pj_mutex_unlock(resolver->mutex); 804 778 805 /* This cached response is still valid. Just return this 779 806 * response to caller. … … 784 811 785 812 /* Done. No host resolution is necessary */ 813 pj_mutex_lock(resolver->mutex); 814 815 /* Decrement the ref counter. Also check if it is time to free 816 * the cache (as it has been expired). 817 */ 818 cache->ref_cnt--; 819 if (cache->ref_cnt <= 0) 820 free_entry(resolver, cache); 786 821 787 822 /* Must return PJ_SUCCESS */ … … 796 831 pj_hash_set(NULL, resolver->hrescache, &key, sizeof(key), 0, NULL); 797 832 798 /* Store the entry into free nodes */ 799 free_entry(resolver, cache); 833 /* Also free the cache, if it is not being used (by callback). */ 834 cache->ref_cnt--; 835 if (cache->ref_cnt <= 0) 836 free_entry(resolver, cache); 800 837 801 838 /* Must continue with creating a query now */ … … 1208 1245 if (cache == NULL) { 1209 1246 cache = alloc_entry(resolver); 1247 } else { 1248 /* Reset cache to avoid bloated cache pool */ 1249 reset_entry(&cache); 1210 1250 } 1211 1251 … … 1216 1256 * the name being requested. 1217 1257 */ 1218 cache->pkt = NULL;1219 1258 pj_dns_packet_dup(cache->pool, pkt, 1220 1259 PJ_DNS_NO_NS | PJ_DNS_NO_AR,
Note: See TracChangeset
for help on using the changeset viewer.