Moved the definition of the BlockAddressPool class into block_allocator.cpp, as it's
not used outside of it. Added tracking for the last transaction in the block cache; that way it can test if the last transaction has been closed before opening a new one. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13022 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+24
@@ -23,6 +23,30 @@
|
|||||||
#endif
|
#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;
|
static class BlockAddressPool sBlockAddressPool;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+8
@@ -82,6 +82,9 @@ static void
|
|||||||
delete_transaction(block_cache *cache, cache_transaction *transaction)
|
delete_transaction(block_cache *cache, cache_transaction *transaction)
|
||||||
{
|
{
|
||||||
hash_remove(cache->transaction_hash, transaction);
|
hash_remove(cache->transaction_hash, transaction);
|
||||||
|
if (cache->last_transaction == transaction)
|
||||||
|
cache->last_transaction = NULL;
|
||||||
|
|
||||||
delete transaction;
|
delete transaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,6 +135,7 @@ block_cache::block_cache(int _fd, off_t numBlocks, size_t blockSize)
|
|||||||
max_blocks(numBlocks),
|
max_blocks(numBlocks),
|
||||||
block_size(blockSize),
|
block_size(blockSize),
|
||||||
next_transaction_id(1),
|
next_transaction_id(1),
|
||||||
|
last_transaction(NULL),
|
||||||
transaction_hash(NULL),
|
transaction_hash(NULL),
|
||||||
ranges_hash(NULL),
|
ranges_hash(NULL),
|
||||||
free_ranges(NULL)
|
free_ranges(NULL)
|
||||||
@@ -522,6 +526,9 @@ cache_start_transaction(void *_cache)
|
|||||||
{
|
{
|
||||||
block_cache *cache = (block_cache *)_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;
|
cache_transaction *transaction = new cache_transaction;
|
||||||
if (transaction == NULL)
|
if (transaction == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
@@ -532,6 +539,7 @@ cache_start_transaction(void *_cache)
|
|||||||
transaction->notification_hook = NULL;
|
transaction->notification_hook = NULL;
|
||||||
transaction->notification_data = NULL;
|
transaction->notification_data = NULL;
|
||||||
transaction->open = true;
|
transaction->open = true;
|
||||||
|
cache->last_transaction = transaction;
|
||||||
|
|
||||||
TRACE(("cache_transaction_start(): id %ld started\n", transaction->id));
|
TRACE(("cache_transaction_start(): id %ld started\n", transaction->id));
|
||||||
|
|
||||||
|
|||||||
+1
-24
@@ -90,13 +90,13 @@ struct block_range {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct block_cache {
|
struct block_cache {
|
||||||
|
|
||||||
hash_table *hash;
|
hash_table *hash;
|
||||||
benaphore lock;
|
benaphore lock;
|
||||||
int fd;
|
int fd;
|
||||||
off_t max_blocks;
|
off_t max_blocks;
|
||||||
size_t block_size;
|
size_t block_size;
|
||||||
int32 next_transaction_id;
|
int32 next_transaction_id;
|
||||||
|
cache_transaction *last_transaction;
|
||||||
hash_table *transaction_hash;
|
hash_table *transaction_hash;
|
||||||
|
|
||||||
hash_table *ranges_hash;
|
hash_table *ranges_hash;
|
||||||
@@ -120,29 +120,6 @@ struct block_cache {
|
|||||||
void *Allocate();
|
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
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|||||||
Reference in New Issue
Block a user