diff --git a/src/system/kernel/cache/block_allocator.cpp b/src/system/kernel/cache/block_allocator.cpp index 9c3b5c17ed..e4cbc71763 100644 --- a/src/system/kernel/cache/block_allocator.cpp +++ b/src/system/kernel/cache/block_allocator.cpp @@ -23,6 +23,30 @@ #endif +class BlockAddressPool { + public: + BlockAddressPool(); + ~BlockAddressPool(); + + status_t InitCheck() const { return fArea >= B_OK ? B_OK : fArea; } + + size_t RangeSize() const { return kBlockRangeSize; } + size_t RangeShift() const { return kBlockRangeShift; } + addr_t BaseAddress() const { return fBase; } + + addr_t Get(); + void Put(addr_t address); + + private: + benaphore fLock; + area_id fArea; + addr_t fBase; + addr_t fFirstFree; + int32 fNextFree; + int32 fFreeList[kBlockAddressSize / kBlockRangeSize]; +}; + + static class BlockAddressPool sBlockAddressPool; diff --git a/src/system/kernel/cache/block_cache.cpp b/src/system/kernel/cache/block_cache.cpp index f96202c815..d989ce812c 100644 --- a/src/system/kernel/cache/block_cache.cpp +++ b/src/system/kernel/cache/block_cache.cpp @@ -82,6 +82,9 @@ static void delete_transaction(block_cache *cache, cache_transaction *transaction) { hash_remove(cache->transaction_hash, transaction); + if (cache->last_transaction == transaction) + cache->last_transaction = NULL; + delete transaction; } @@ -132,6 +135,7 @@ block_cache::block_cache(int _fd, off_t numBlocks, size_t blockSize) max_blocks(numBlocks), block_size(blockSize), next_transaction_id(1), + last_transaction(NULL), transaction_hash(NULL), ranges_hash(NULL), free_ranges(NULL) @@ -522,6 +526,9 @@ cache_start_transaction(void *_cache) { block_cache *cache = (block_cache *)_cache; + if (cache->last_transaction && cache->last_transaction->open) + panic("last transaction (%ld) still open!\n", cache->last_transaction->id); + cache_transaction *transaction = new cache_transaction; if (transaction == NULL) return B_NO_MEMORY; @@ -532,6 +539,7 @@ cache_start_transaction(void *_cache) transaction->notification_hook = NULL; transaction->notification_data = NULL; transaction->open = true; + cache->last_transaction = transaction; TRACE(("cache_transaction_start(): id %ld started\n", transaction->id)); diff --git a/src/system/kernel/cache/block_cache_private.h b/src/system/kernel/cache/block_cache_private.h index bea33bc760..5691311691 100644 --- a/src/system/kernel/cache/block_cache_private.h +++ b/src/system/kernel/cache/block_cache_private.h @@ -90,13 +90,13 @@ struct block_range { }; struct block_cache { - hash_table *hash; benaphore lock; int fd; off_t max_blocks; size_t block_size; int32 next_transaction_id; + cache_transaction *last_transaction; hash_table *transaction_hash; hash_table *ranges_hash; @@ -120,29 +120,6 @@ struct block_cache { void *Allocate(); }; -class BlockAddressPool { - public: - BlockAddressPool(); - ~BlockAddressPool(); - - status_t InitCheck() const { return fArea >= B_OK ? B_OK : fArea; } - - size_t RangeSize() const { return kBlockRangeSize; } - size_t RangeShift() const { return kBlockRangeShift; } - addr_t BaseAddress() const { return fBase; } - - addr_t Get(); - void Put(addr_t address); - - private: - benaphore fLock; - area_id fArea; - addr_t fBase; - addr_t fFirstFree; - int32 fNextFree; - int32 fFreeList[kBlockAddressSize / kBlockRangeSize]; -}; - #ifdef __cplusplus extern "C" {