1/*- 2 * Copyright (c) 2005 Michael Bushkov <bushman@rsu.ru> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 12 unchanged lines hidden (view full) --- 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 */ 27 28#include <sys/cdefs.h> |
29__FBSDID("$FreeBSD: head/usr.sbin/nscd/cachelib.c 194095 2009-06-13 00:54:52Z des $"); |
30 31#include <sys/time.h> 32 33#include <assert.h> 34#include <stdlib.h> 35#include <string.h> 36 37#include "cachelib.h" --- 103 unchanged lines hidden (view full) --- 141 retval = 0; 142 for (i = 0; i < hp->key_size; ++i) 143 retval = (127 * retval + (unsigned char)hp->key[i]) % 144 cache_entries_size; 145 146 return retval; 147} 148 |
149HASHTABLE_PROTOTYPE(cache_ht_, cache_ht_item_, struct cache_ht_item_data_); |
150HASHTABLE_GENERATE(cache_ht_, cache_ht_item_, struct cache_ht_item_data_, data, 151 ht_item_hash_func, ht_items_cmp_func); 152 153/* 154 * Routines to sort and search the entries by name 155 */ 156static int 157entries_bsearch_cmp_func(const void *key, const void *ent) --- 129 unchanged lines hidden (view full) --- 287{ 288 struct cache_mp_entry_ *mp_entry; 289 struct cache_common_entry_ *common_entry; 290 struct cache_ht_item_ *ht_item; 291 struct cache_ht_item_data_ *ht_item_data; 292 struct cache_policy_ *policy; 293 struct cache_policy_item_ *item, *next_item; 294 size_t entry_size; |
295 unsigned int i; |
296 297 if (entry->params->entry_type == CET_COMMON) { 298 common_entry = (struct cache_common_entry_ *)entry; 299 300 entry_size = 0; 301 HASHTABLE_FOREACH(&(common_entry->items), ht_item) { 302 HASHTABLE_ENTRY_FOREACH(ht_item, data, ht_item_data) 303 { --- 88 unchanged lines hidden (view full) --- 392 policy->remove_item_func(policy, item); 393 394 memset(&ht_key, 0, sizeof(struct cache_ht_item_data_)); 395 ht_key.key = item->key; 396 ht_key.key_size = item->key_size; 397 398 hash = HASHTABLE_CALCULATE_HASH(cache_ht_, &entry->items, 399 &ht_key); |
400 assert(hash < HASHTABLE_ENTRIES_COUNT(&entry->items)); 401 402 ht_item = HASHTABLE_GET_ENTRY(&(entry->items), hash); 403 ht_item_data = HASHTABLE_ENTRY_FIND(cache_ht_, ht_item, 404 &ht_key); 405 assert(ht_item_data != NULL); 406 free(ht_item_data->key); 407 free(ht_item_data->value); --- 305 unchanged lines hidden (view full) --- 713 714 memset(&item_data, 0, sizeof(struct cache_ht_item_data_)); 715 /* can't avoid the cast here */ 716 item_data.key = (char *)key; 717 item_data.key_size = key_size; 718 719 hash = HASHTABLE_CALCULATE_HASH(cache_ht_, &common_entry->items, 720 &item_data); |
721 assert(hash < HASHTABLE_ENTRIES_COUNT(&common_entry->items)); 722 723 item = HASHTABLE_GET_ENTRY(&(common_entry->items), hash); 724 find_res = HASHTABLE_ENTRY_FIND(cache_ht_, item, &item_data); 725 if (find_res == NULL) { 726 TRACE_OUT(cache_read); 727 return (-1); 728 } --- 87 unchanged lines hidden (view full) --- 816 817 memset(&item_data, 0, sizeof(struct cache_ht_item_data_)); 818 /* can't avoid the cast here */ 819 item_data.key = (char *)key; 820 item_data.key_size = key_size; 821 822 hash = HASHTABLE_CALCULATE_HASH(cache_ht_, &common_entry->items, 823 &item_data); |
824 assert(hash < HASHTABLE_ENTRIES_COUNT(&common_entry->items)); 825 826 item = HASHTABLE_GET_ENTRY(&(common_entry->items), hash); 827 find_res = HASHTABLE_ENTRY_FIND(cache_ht_, item, &item_data); 828 if (find_res != NULL) { 829 TRACE_OUT(cache_write); 830 return (-1); 831 } --- 387 unchanged lines hidden --- |