Changeset bc216a0 in mainline for uspace/lib/block/libblock.c
- Timestamp:
- 2012-08-07T22:13:44Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- da68871a
- Parents:
- b17518e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/block/libblock.c
rb17518e rbc216a0 254 254 } 255 255 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) 277 { 278 block_t *b = hash_table_get_instance(item, block_t, hash_link); 279 return b->lba == MERGE_LOUP32(key[0], key[1]); 256 static size_t cache_key_hash(void *key) 257 { 258 aoff64_t *lba = (aoff64_t*)key; 259 return *lba; 260 } 261 262 static size_t cache_hash(const ht_link_t *item) 263 { 264 block_t *b = hash_table_get_inst(item, block_t, hash_link); 265 return b->lba; 266 } 267 268 static bool cache_key_equal(void *key, const ht_link_t *item) 269 { 270 aoff64_t *lba = (aoff64_t*)key; 271 block_t *b = hash_table_get_inst(item, block_t, hash_link); 272 return b->lba == *lba; 280 273 } 281 274 … … 284 277 .hash = cache_hash, 285 278 .key_hash = cache_key_hash, 286 . match = cache_match,279 .key_equal = cache_key_equal, 287 280 .equal = 0, 288 281 .remove_callback = 0 … … 317 310 cache->blocks_cluster = cache->lblock_size / devcon->pblock_size; 318 311 319 if (!hash_table_create(&cache->block_hash, 0, 2, &cache_ops)) {312 if (!hash_table_create(&cache->block_hash, 0, 0, &cache_ops)) { 320 313 free(cache); 321 314 return ENOMEM; … … 355 348 } 356 349 357 unsigned long key[2] = { 358 LOWER32(b->lba), 359 UPPER32(b->lba) 360 }; 361 hash_table_remove(&cache->block_hash, key, 2); 350 hash_table_remove_item(&cache->block_hash, &b->hash_link); 362 351 363 352 free(b->data); … … 391 380 fibril_rwlock_initialize(&b->contents_lock); 392 381 link_initialize(&b->free_link); 393 link_initialize(&b->hash_link);394 382 } 395 383 … … 411 399 cache_t *cache; 412 400 block_t *b; 413 link_t *l; 414 unsigned long key[2] = { 415 LOWER32(ba), 416 UPPER32(ba) 417 }; 401 link_t *link; 418 402 419 403 int rc; … … 431 415 432 416 fibril_mutex_lock(&cache->lock); 433 l = hash_table_find(&cache->block_hash, key);434 if ( l) {417 ht_link_t *hlink = hash_table_find(&cache->block_hash, &ba); 418 if (hlink) { 435 419 found: 436 420 /* 437 421 * We found the block in the cache. 438 422 */ 439 b = hash_table_get_inst ance(l, block_t, hash_link);423 b = hash_table_get_inst(hlink, block_t, hash_link); 440 424 fibril_mutex_lock(&b->lock); 441 425 if (b->refcnt++ == 0) … … 475 459 goto out; 476 460 } 477 l = list_first(&cache->free_list);478 b = list_get_instance(l , block_t, free_link);461 link = list_first(&cache->free_list); 462 b = list_get_instance(link, block_t, free_link); 479 463 480 464 fibril_mutex_lock(&b->lock); … … 516 500 goto retry; 517 501 } 518 l = hash_table_find(&cache->block_hash, key);519 if ( l) {502 hlink = hash_table_find(&cache->block_hash, &ba); 503 if (hlink) { 520 504 /* 521 505 * Someone else must have already … … 539 523 */ 540 524 list_remove(&b->free_link); 541 unsigned long temp_key[2] = { 542 LOWER32(b->lba), 543 UPPER32(b->lba) 544 }; 545 hash_table_remove(&cache->block_hash, temp_key, 2); 525 hash_table_remove_item(&cache->block_hash, &b->hash_link); 546 526 } 547 527 … … 663 643 * Take the block out of the cache and free it. 664 644 */ 665 unsigned long key[2] = { 666 LOWER32(block->lba), 667 UPPER32(block->lba) 668 }; 669 hash_table_remove(&cache->block_hash, key, 2); 645 hash_table_remove_item(&cache->block_hash, &block->hash_link); 670 646 fibril_mutex_unlock(&block->lock); 671 647 free(block->data);
Note:
See TracChangeset
for help on using the changeset viewer.