Changeset 0ca7286 in mainline for uspace/lib/block/libblock.c
- Timestamp:
- 2012-07-21T11:19:27Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 2732c94
- Parents:
- 1c1da4b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/block/libblock.c
r1c1da4b r0ca7286 62 62 static LIST_INITIALIZE(dcl); 63 63 64 #define CACHE_BUCKETS_LOG2 1065 #define CACHE_BUCKETS (1 << CACHE_BUCKETS_LOG2)66 64 67 65 typedef struct { … … 256 254 } 257 255 258 static hash_index_t cache_hash(unsigned long *key) 259 { 260 return MERGE_LOUP32(key[0], key[1]) & (CACHE_BUCKETS - 1); 261 } 262 263 static int cache_compare(unsigned long *key, hash_count_t keys, link_t *item) 256 static size_t cache_key_hash(unsigned long *key) 257 { 258 /* As recommended by Effective Java, 2nd Edition. */ 259 size_t hash = 17; 260 hash = 31 * hash + key[1]; 261 hash = 31 * hash + key[0]; 262 return hash; 263 } 264 265 static size_t cache_hash(const link_t *item) 266 { 267 block_t *b = hash_table_get_instance(item, block_t, hash_link); 268 unsigned long key[] = { 269 LOWER32(b->lba), 270 UPPER32(b->lba) 271 }; 272 273 return cache_key_hash(key); 274 } 275 276 static bool cache_match(unsigned long *key, size_t keys, const link_t *item) 264 277 { 265 278 block_t *b = hash_table_get_instance(item, block_t, hash_link); … … 267 280 } 268 281 269 static void cache_remove_callback(link_t *item) 270 { 271 } 272 273 static hash_table_operations_t cache_ops = { 282 283 static hash_table_ops_t cache_ops = { 274 284 .hash = cache_hash, 275 .compare = cache_compare, 276 .remove_callback = cache_remove_callback 285 .key_hash = cache_key_hash, 286 .match = cache_match, 287 .equal = 0, 288 .remove_callback = 0 277 289 }; 278 290 … … 305 317 cache->blocks_cluster = cache->lblock_size / devcon->pblock_size; 306 318 307 if (!hash_table_create(&cache->block_hash, CACHE_BUCKETS, 2, 308 &cache_ops)) { 319 if (!hash_table_create(&cache->block_hash, 0, 2, &cache_ops)) { 309 320 free(cache); 310 321 return ENOMEM; … … 540 551 b->lba = ba; 541 552 b->pba = ba_ltop(devcon, b->lba); 542 hash_table_insert(&cache->block_hash, key,&b->hash_link);553 hash_table_insert(&cache->block_hash, &b->hash_link); 543 554 544 555 /*
Note:
See TracChangeset
for help on using the changeset viewer.