Changeset b800b0e in mainline for uspace/lib/block/block.c
- Timestamp:
- 2012-10-23T13:16:49Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6ecf5b8
- Parents:
- 32b3a12 (diff), b2ac3998 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/block/block.c
r32b3a12 rb800b0e 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 { … … 233 231 } 234 232 235 static hash_index_t cache_hash(unsigned long *key) 236 { 237 return MERGE_LOUP32(key[0], key[1]) & (CACHE_BUCKETS - 1); 238 } 239 240 static int cache_compare(unsigned long *key, hash_count_t keys, link_t *item) 241 { 242 block_t *b = hash_table_get_instance(item, block_t, hash_link); 243 return b->lba == MERGE_LOUP32(key[0], key[1]); 244 } 245 246 static void cache_remove_callback(link_t *item) 247 { 248 } 249 250 static hash_table_operations_t cache_ops = { 233 static size_t cache_key_hash(void *key) 234 { 235 aoff64_t *lba = (aoff64_t*)key; 236 return *lba; 237 } 238 239 static size_t cache_hash(const ht_link_t *item) 240 { 241 block_t *b = hash_table_get_inst(item, block_t, hash_link); 242 return b->lba; 243 } 244 245 static bool cache_key_equal(void *key, const ht_link_t *item) 246 { 247 aoff64_t *lba = (aoff64_t*)key; 248 block_t *b = hash_table_get_inst(item, block_t, hash_link); 249 return b->lba == *lba; 250 } 251 252 253 static hash_table_ops_t cache_ops = { 251 254 .hash = cache_hash, 252 .compare = cache_compare, 253 .remove_callback = cache_remove_callback 255 .key_hash = cache_key_hash, 256 .key_equal = cache_key_equal, 257 .equal = NULL, 258 .remove_callback = NULL 254 259 }; 255 260 … … 282 287 cache->blocks_cluster = cache->lblock_size / devcon->pblock_size; 283 288 284 if (!hash_table_create(&cache->block_hash, CACHE_BUCKETS, 2, 285 &cache_ops)) { 289 if (!hash_table_create(&cache->block_hash, 0, 0, &cache_ops)) { 286 290 free(cache); 287 291 return ENOMEM; … … 321 325 } 322 326 323 unsigned long key[2] = { 324 LOWER32(b->lba), 325 UPPER32(b->lba) 326 }; 327 hash_table_remove(&cache->block_hash, key, 2); 327 hash_table_remove_item(&cache->block_hash, &b->hash_link); 328 328 329 329 free(b->data); … … 357 357 fibril_rwlock_initialize(&b->contents_lock); 358 358 link_initialize(&b->free_link); 359 link_initialize(&b->hash_link);360 359 } 361 360 … … 377 376 cache_t *cache; 378 377 block_t *b; 379 link_t *l; 380 unsigned long key[2] = { 381 LOWER32(ba), 382 UPPER32(ba) 383 }; 378 link_t *link; 384 379 385 380 int rc; … … 397 392 398 393 fibril_mutex_lock(&cache->lock); 399 l = hash_table_find(&cache->block_hash, key);400 if ( l) {394 ht_link_t *hlink = hash_table_find(&cache->block_hash, &ba); 395 if (hlink) { 401 396 found: 402 397 /* 403 398 * We found the block in the cache. 404 399 */ 405 b = hash_table_get_inst ance(l, block_t, hash_link);400 b = hash_table_get_inst(hlink, block_t, hash_link); 406 401 fibril_mutex_lock(&b->lock); 407 402 if (b->refcnt++ == 0) … … 441 436 goto out; 442 437 } 443 l = list_first(&cache->free_list);444 b = list_get_instance(l , block_t, free_link);438 link = list_first(&cache->free_list); 439 b = list_get_instance(link, block_t, free_link); 445 440 446 441 fibril_mutex_lock(&b->lock); … … 479 474 goto retry; 480 475 } 481 l = hash_table_find(&cache->block_hash, key);482 if ( l) {476 hlink = hash_table_find(&cache->block_hash, &ba); 477 if (hlink) { 483 478 /* 484 479 * Someone else must have already … … 502 497 */ 503 498 list_remove(&b->free_link); 504 unsigned long temp_key[2] = { 505 LOWER32(b->lba), 506 UPPER32(b->lba) 507 }; 508 hash_table_remove(&cache->block_hash, temp_key, 2); 499 hash_table_remove_item(&cache->block_hash, &b->hash_link); 509 500 } 510 501 … … 514 505 b->lba = ba; 515 506 b->pba = ba_ltop(devcon, b->lba); 516 hash_table_insert(&cache->block_hash, key,&b->hash_link);507 hash_table_insert(&cache->block_hash, &b->hash_link); 517 508 518 509 /* … … 622 613 * Take the block out of the cache and free it. 623 614 */ 624 unsigned long key[2] = { 625 LOWER32(block->lba), 626 UPPER32(block->lba) 627 }; 628 hash_table_remove(&cache->block_hash, key, 2); 615 hash_table_remove_item(&cache->block_hash, &block->hash_link); 629 616 fibril_mutex_unlock(&block->lock); 630 617 free(block->data);
Note:
See TracChangeset
for help on using the changeset viewer.