enforce smart pointers for block cache.

git-svn-id: https://profuse.googlecode.com/svn/branches/profuse_interim@344 aa027e90-d47c-11dd-86d7-074df07e0730
This commit is contained in:
ksherlock 2011-02-22 02:06:56 +00:00
parent c44145f551
commit c9b260b753
9 changed files with 26 additions and 9 deletions

View File

@ -58,6 +58,10 @@ using ProFUSE::POSIXException;
//typedef std::vector<ConcreteBlockCache::Entry *>::iterator EntryIter;
BlockCachePointer ConcreteBlockCache::Create(BlockDevicePointer device, unsigned size)
{
return BlockCachePointer(new ConcreteBlockCache(device, size));
}
ConcreteBlockCache::ConcreteBlockCache(BlockDevicePointer device, unsigned size) :
BlockCache(device)

View File

@ -9,7 +9,9 @@ namespace Device {
class ConcreteBlockCache : public BlockCache {
public:
ConcreteBlockCache(BlockDevicePointer device, unsigned size = 16);
static BlockCachePointer Create(BlockDevicePointer device, unsigned size = 16);
virtual ~ConcreteBlockCache();
virtual void sync();
@ -21,8 +23,11 @@ public:
virtual void markDirty(unsigned block);
private:
ConcreteBlockCache(BlockDevicePointer device, unsigned size);
struct Entry {
unsigned block;
unsigned count;

View File

@ -19,6 +19,11 @@ using namespace Device;
using ProFUSE::Exception;
using ProFUSE::POSIXException;
BlockCachePointer MappedBlockCache::Create(BlockDevicePointer device, void *data)
{
return BlockCachePointer(new MappedBlockCache(device, data));
}
MappedBlockCache::MappedBlockCache(BlockDevicePointer device, void *data) :
BlockCache(device)

View File

@ -8,7 +8,8 @@ namespace Device {
class MappedBlockCache : public BlockCache {
public:
MappedBlockCache(BlockDevicePointer device, void *data);
static BlockCachePointer Create(BlockDevicePointer device, void *data);
virtual ~MappedBlockCache();
virtual void sync();
@ -22,7 +23,9 @@ class MappedBlockCache : public BlockCache {
virtual void markDirty(unsigned block);
private:
MappedBlockCache(BlockDevicePointer device, void *data);
void sync(unsigned block);
uint8_t *_data;

View File

@ -237,5 +237,5 @@ BlockCachePointer BlockDevice::createBlockCache()
{
unsigned b = blocks();
unsigned size = std::max(16u, b / 16);
return BlockCachePointer(new ConcreteBlockCache(shared_from_this(), size));
return ConcreteBlockCache::Create(shared_from_this(), size);
}

View File

@ -161,6 +161,6 @@ DavexDiskImage *DavexDiskImage::Create(const char *name, size_t blocks, const ch
BlockCachePointer DavexDiskImage::createBlockCache()
{
// need a smart pointer, but only have this....
return BlockCachePointer(new MappedBlockCache(shared_from_this(), 512 + (uint8_t *)address()));
return MappedBlockCache::Create(shared_from_this(), 512 + (uint8_t *)address());
}

View File

@ -224,5 +224,5 @@ BlockCachePointer DiskCopy42Image::createBlockCache()
if (!readOnly()) _changed = true;
return BlockCachePointer(new MappedBlockCache(shared_from_this(), address()));
return MappedBlockCache::Create(shared_from_this(), address());
}

View File

@ -140,7 +140,7 @@ void ProDOSOrderDiskImage::Validate(MappedFile *f)
BlockCachePointer ProDOSOrderDiskImage::createBlockCache()
{
return BlockCachePointer(new MappedBlockCache(shared_from_this(), address()));
return MappedBlockCache::Create(shared_from_this(), address());
}
#pragma mark -

View File

@ -145,7 +145,7 @@ BlockCachePointer UniversalDiskImage::createBlockCache()
{
if (_format == 1)
{
return BlockCachePointer(new MappedBlockCache(shared_from_this(), _dataOffset + (uint8_t *)address()));
return MappedBlockCache::Create(shared_from_this(), _dataOffset + (uint8_t *)address());
}
return DiskImage::createBlockCache();