Lines Matching refs:cache

166 static fssh_status_t write_cached_block(block_cache* cache, cached_block* block,
215 flush_pending_notifications(block_cache* cache)
220 cache_notification* notification = cache->pending_notifications.Head();
228 cache->pending_notifications.Remove(notification);
286 add_notification(block_cache* cache, cache_notification* notification,
298 cache->pending_notifications.Add(notification);
312 notify_transaction_listeners(block_cache* cache, cache_transaction* transaction,
328 add_notification(cache, listener, event, remove);
335 flush_pending_notifications(cache);
343 remove_transaction_listeners(block_cache* cache, cache_transaction* transaction)
356 add_transaction_listener(block_cache* cache, cache_transaction* transaction,
420 delete_transaction(block_cache* cache, cache_transaction* transaction)
422 if (cache->last_transaction == transaction)
423 cache->last_transaction = NULL;
425 remove_transaction_listeners(cache, transaction);
431 lookup_transaction(block_cache* cache, int32_t id)
433 return (cache_transaction*)hash_lookup(cache->transaction_hash, &id);
499 fssh_mutex_init(&lock, "block cache");
563 // if we hit the limit of blocks to cache�� try to free one or more
660 put_cached_block(block_cache* cache, cached_block* block)
664 && memcmp(block->current_data, block->compare, cache->block_size)) {
669 write_cached_block(cache, block);
672 cache->Free(block->compare);
681 cache->RemoveBlock(block);
685 cache->unused_blocks.Add(block);
689 if (cache->allocated_block_count > kMaxBlockCount) {
690 cache->RemoveUnusedBlocks(INT32_MAX,
691 cache->allocated_block_count - kMaxBlockCount);
697 put_cached_block(block_cache* cache, fssh_off_t blockNumber)
699 if (blockNumber < 0 || blockNumber >= cache->max_blocks) {
701 " (max %" FSSH_B_PRIdOFF ")", blockNumber, cache->max_blocks - 1);
704 cached_block* block = (cached_block*)hash_lookup(cache->hash, &blockNumber);
706 put_cached_block(cache, block);
716 not already in the cache. The block you retrieve may contain random
720 get_cached_block(block_cache* cache, fssh_off_t blockNumber, bool* _allocated,
723 if (blockNumber < 0 || blockNumber >= cache->max_blocks) {
725 " (max %" FSSH_B_PRIdOFF ")", blockNumber, cache->max_blocks - 1);
729 cached_block* block = (cached_block*)hash_lookup(cache->hash,
734 // read block into cache
735 block = cache->NewBlock(blockNumber);
739 hash_insert(cache->hash, block);
744 int32_t blockSize = cache->block_size;
746 if (fssh_read_pos(cache->fd, blockNumber * blockSize, block->current_data,
748 cache->RemoveBlock(block);
757 cache->unused_blocks.Remove(block);
776 get_writable_cached_block(block_cache* cache, fssh_off_t blockNumber, fssh_off_t base,
782 if (blockNumber < 0 || blockNumber >= cache->max_blocks) {
785 cache->max_blocks - 1);
791 fssh_status_t status = get_cached_block(cache, blockNumber, &allocated,
801 fssh_memset(block->current_data, 0, cache->block_size);
816 put_cached_block(cache, block);
821 transaction = lookup_transaction(cache, transactionID);
825 put_cached_block(cache, block);
830 put_cached_block(cache, block);
847 block->original_data = cache->Allocate();
850 put_cached_block(cache, block);
854 fssh_memcpy(block->original_data, block->current_data, cache->block_size);
858 block->parent_data = cache->Allocate();
862 put_cached_block(cache, block);
866 fssh_memcpy(block->parent_data, block->current_data, cache->block_size);
873 fssh_memset(block->current_data, 0, cache->block_size);
889 write_cached_block(block_cache* cache, cached_block* block,
893 int32_t blockSize = cache->block_size;
901 fssh_ssize_t written = fssh_write_pos(cache->fd, block->block_number * blockSize,
920 cache->Free(block->original_data);
926 TRACE(("cache transaction %ld finished!\n", previous->id));
928 notify_transaction_listeners(cache, previous, FSSH_TRANSACTION_WRITTEN);
931 hash_remove(cache->transaction_hash, previous);
932 delete_transaction(cache, previous);
939 cache->unused_blocks.Add(block);
948 You must not hold the \a cache lock when calling this function.
951 wait_for_notifications(block_cache* cache)
960 fssh_mutex_init(&sNotificationsLock, "block cache notifications");
977 block_cache* cache = (block_cache*)_cache;
978 MutexLocker locker(&cache->lock);
980 if (cache->last_transaction && cache->last_transaction->open) {
982 (int)cache->last_transaction->id);
989 transaction->id = fssh_atomic_add(&cache->next_transaction_id, 1);
990 cache->last_transaction = transaction;
994 hash_insert(cache->transaction_hash, transaction);
1003 block_cache* cache = (block_cache*)_cache;
1004 MutexLocker locker(&cache->lock);
1010 hash_open(cache->transaction_hash, &iterator);
1014 cache->transaction_hash, &iterator)) != NULL) {
1020 status = write_cached_block(cache, transaction->blocks.Head(),
1026 hash_remove_current(cache->transaction_hash, &iterator);
1027 delete_transaction(cache, transaction);
1031 hash_close(cache->transaction_hash, &iterator, false);
1034 wait_for_notifications(cache);
1045 block_cache* cache = (block_cache*)_cache;
1046 MutexLocker locker(&cache->lock);
1050 cache_transaction* transaction = lookup_transaction(cache, id);
1056 notify_transaction_listeners(cache, transaction, FSSH_TRANSACTION_ENDED);
1058 if (add_transaction_listener(cache, transaction, FSSH_TRANSACTION_WRITTEN,
1072 write_cached_block(cache, block);
1076 cache->DiscardBlock(block);
1082 cache->Free(block->original_data);
1087 cache->Free(block->parent_data);
1107 block_cache* cache = (block_cache*)_cache;
1108 MutexLocker locker(&cache->lock);
1112 cache_transaction* transaction = lookup_transaction(cache, id);
1118 notify_transaction_listeners(cache, transaction, FSSH_TRANSACTION_ABORTED);
1130 fssh_memcpy(block->current_data, block->original_data, cache->block_size);
1131 cache->Free(block->original_data);
1136 cache->Free(block->parent_data);
1145 hash_remove(cache->transaction_hash, transaction);
1146 delete_transaction(cache, transaction);
1159 block_cache* cache = (block_cache*)_cache;
1160 MutexLocker locker(&cache->lock);
1164 cache_transaction* transaction = lookup_transaction(cache, id);
1177 newTransaction->id = fssh_atomic_add(&cache->next_transaction_id, 1);
1179 notify_transaction_listeners(cache, transaction, FSSH_TRANSACTION_ENDED);
1181 if (add_transaction_listener(cache, transaction, FSSH_TRANSACTION_WRITTEN,
1197 write_cached_block(cache, block);
1200 cache->DiscardBlock(block);
1208 cache->Free(block->original_data);
1242 hash_insert(cache->transaction_hash, newTransaction);
1243 cache->last_transaction = newTransaction;
1252 block_cache* cache = (block_cache*)_cache;
1253 MutexLocker locker(&cache->lock);
1257 cache_transaction* transaction = lookup_transaction(cache, id);
1265 notify_transaction_listeners(cache, transaction, FSSH_TRANSACTION_ABORTED);
1279 cache->block_size);
1286 cache->block_size);
1287 cache->Free(block->parent_data);
1305 block_cache* cache = (block_cache*)_cache;
1306 MutexLocker locker(&cache->lock);
1310 cache_transaction* transaction = lookup_transaction(cache, id);
1316 notify_transaction_listeners(cache, transaction, FSSH_TRANSACTION_ENDED);
1333 cache->DiscardBlock(block);
1342 cache->Free(block->parent_data);
1388 block_cache* cache = (block_cache*)_cache;
1390 MutexLocker locker(&cache->lock);
1392 cache_transaction* transaction = lookup_transaction(cache, id);
1431 block_cache* cache = (block_cache*)_cache;
1432 MutexLocker locker(&cache->lock);
1434 cache_transaction* transaction = lookup_transaction(cache, id);
1445 block_cache* cache = (block_cache*)_cache;
1446 MutexLocker locker(&cache->lock);
1448 cache_transaction* transaction = lookup_transaction(cache, id);
1459 block_cache* cache = (block_cache*)_cache;
1460 MutexLocker locker(&cache->lock);
1462 cache_transaction* transaction = lookup_transaction(cache, id);
1474 block_cache* cache = (block_cache*)_cache;
1475 MutexLocker locker(&cache->lock);
1477 cached_block* block = (cached_block*)hash_lookup(cache->hash, &blockNumber);
1484 // #pragma mark - public block cache API
1490 block_cache* cache = (block_cache*)_cache;
1493 fssh_block_cache_sync(cache);
1495 fssh_mutex_lock(&cache->lock);
1501 while ((block = (cached_block*)hash_remove_first(cache->hash,
1503 cache->FreeBlock(block);
1511 cache->transaction_hash, &cookie)) != NULL) {
1515 delete cache;
1522 block_cache* cache = new(std::nothrow) block_cache(fd, numBlocks, blockSize,
1524 if (cache == NULL)
1527 if (cache->Init() != FSSH_B_OK) {
1528 delete cache;
1532 return cache;
1539 block_cache* cache = (block_cache*)_cache;
1544 MutexLocker locker(&cache->lock);
1546 hash_open(cache->hash, &iterator);
1549 while ((block = (cached_block*)hash_next(cache->hash, &iterator)) != NULL) {
1552 fssh_status_t status = write_cached_block(cache, block);
1558 hash_close(cache->hash, &iterator, false);
1567 block_cache* cache = (block_cache*)_cache;
1572 if (blockNumber < 0 || blockNumber >= cache->max_blocks) {
1574 " (max %" FSSH_B_PRIdOFF ")", blockNumber, cache->max_blocks - 1);
1578 MutexLocker locker(&cache->lock);
1581 cached_block* block = (cached_block*)hash_lookup(cache->hash,
1588 fssh_status_t status = write_cached_block(cache, block);
1602 block_cache* cache = (block_cache*)_cache;
1603 MutexLocker locker(&cache->lock);
1606 cached_block* block = (cached_block*)hash_lookup(cache->hash,
1612 write_cached_block(cache, block);
1615 cache->unused_blocks.Remove(block);
1616 cache->RemoveBlock(block);
1635 block_cache* cache = (block_cache*)_cache;
1636 MutexLocker locker(&cache->lock);
1638 if (cache->read_only)
1639 fssh_panic("tried to make block writable on a read-only cache!");
1643 fssh_status_t status = get_writable_cached_block(cache, blockNumber,
1658 block_cache* cache = (block_cache*)_cache;
1659 MutexLocker locker(&cache->lock);
1663 if (cache->read_only)
1664 fssh_panic("tried to get writable block on a read-only cache!");
1666 return get_writable_cached_block(cache, blockNumber, base, length,
1689 block_cache* cache = (block_cache*)_cache;
1690 MutexLocker locker(&cache->lock);
1694 if (cache->read_only)
1695 fssh_panic("tried to get empty writable block on a read-only cache!");
1710 block_cache* cache = (block_cache*)_cache;
1711 MutexLocker locker(&cache->lock);
1715 fssh_status_t status = get_cached_block(cache, blockNumber, &allocated,
1722 block->compare = cache->Allocate();
1724 memcpy(block->compare, block->current_data, cache->block_size);
1754 block_cache* cache = (block_cache*)_cache;
1755 MutexLocker locker(&cache->lock);
1757 cached_block* block = (cached_block*)hash_lookup(cache->hash,
1777 block_cache* cache = (block_cache*)_cache;
1778 MutexLocker locker(&cache->lock);
1780 put_cached_block(cache, blockNumber);