Author: axeld Date: 2010-02-16 15:00:44 +0100 (Tue, 16 Feb 2010) New Revision: 35496 Changeset: http://dev.haiku-os.org/changeset/35496/haiku Modified: haiku/trunk/src/system/kernel/cache/block_cache.cpp Log: * Made cache_end_transaction(), cache_detach_sub_transaction(), and block_cache_discard() use the BlockWriter directly as well. Modified: haiku/trunk/src/system/kernel/cache/block_cache.cpp =================================================================== --- haiku/trunk/src/system/kernel/cache/block_cache.cpp 2010-02-16 13:26:28 UTC (rev 35495) +++ haiku/trunk/src/system/kernel/cache/block_cache.cpp 2010-02-16 14:00:44 UTC (rev 35496) @@ -1101,7 +1101,7 @@ { ASSERT(block->busy_writing); - TRACE(("write_cached_block(block %Ld)\n", block->block_number)); + TRACE(("BlockWriter::_WriteBlock(block %Ld)\n", block->block_number)); TB(Write(fCache, block)); TB2(BlockData(fCache, block, "before write")); @@ -2673,14 +2673,20 @@ BlockWriter writer(cache); cached_block* block = transaction->first_block; + for (; block != NULL; block = block->transaction_next) { + if (block->previous_transaction != NULL) { + // need to write back pending changes + writer.Add(block); + } + } + + writer.Write(); + cached_block* next; - for (; block != NULL; block = next) { + for (block = transaction->first_block; block != NULL; block = next) { next = block->transaction_next; + ASSERT(block->previous_transaction == NULL); - if (block->previous_transaction != NULL) { - // need to write back pending changes - write_cached_block(cache, block); - } if (block->discard) { // This block has been discarded in the transaction cache->DiscardBlock(block); @@ -2798,16 +2804,23 @@ // iterate through all blocks and free the unchanged original contents + BlockWriter writer(cache); cached_block* block = transaction->first_block; + for (; block != NULL; block = block->transaction_next) { + if (block->previous_transaction != NULL) { + // need to write back pending changes + writer.Add(block); + } + } + + writer.Write(); + cached_block* last = NULL; cached_block* next; - for (; block != NULL; block = next) { + for (block = transaction->first_block; block != NULL; block = next) { next = block->transaction_next; + ASSERT(block->previous_transaction == NULL); - if (block->previous_transaction != NULL) { - // need to write back pending changes - write_cached_block(cache, block); - } if (block->discard) { cache->DiscardBlock(block); transaction->main_num_blocks--; @@ -3251,16 +3264,26 @@ block_cache_discard(void* _cache, off_t blockNumber, size_t numBlocks) { block_cache* cache = (block_cache*)_cache; - MutexLocker locker(&cache->lock); + TransactionLocker locker(cache); + BlockWriter writer(cache); + for (; numBlocks > 0; numBlocks--, blockNumber++) { cached_block* block = (cached_block*)hash_lookup(cache->hash, &blockNumber); + if (block != NULL && block->previous_transaction != NULL) + writer.Add(block); + } + + writer.Write(); + + for (; numBlocks > 0; numBlocks--, blockNumber++) { + cached_block* block = (cached_block*)hash_lookup(cache->hash, + &blockNumber); if (block == NULL) continue; - if (block->previous_transaction != NULL) - write_cached_block(cache, block); + ASSERT(block->previous_transaction == NULL); if (block->unused) { cache->unused_blocks.Remove(block);