2009-11-18 15:26:11 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
2011-01-27 23:17:03 +00:00
|
|
|
#ifndef _PACKAGE__HPKG__BLOCK_BUFFER_CACHE_H_
|
|
|
|
#define _PACKAGE__HPKG__BLOCK_BUFFER_CACHE_H_
|
2009-11-18 15:26:11 +00:00
|
|
|
|
|
|
|
|
2011-01-27 23:17:03 +00:00
|
|
|
#include <package/hpkg/BufferCache.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace BPackageKit {
|
|
|
|
|
|
|
|
namespace BHaikuPackage {
|
|
|
|
|
|
|
|
namespace BPrivate {
|
2009-11-18 15:26:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
class BlockBufferCache : public BufferCache {
|
|
|
|
public:
|
|
|
|
BlockBufferCache(size_t blockSize,
|
|
|
|
uint32 maxCachedBlocks);
|
|
|
|
virtual ~BlockBufferCache();
|
|
|
|
|
|
|
|
virtual status_t Init();
|
|
|
|
|
|
|
|
virtual CachedBuffer* GetBuffer(size_t size,
|
|
|
|
CachedBuffer** owner = NULL,
|
|
|
|
bool* _newBuffer = NULL);
|
|
|
|
virtual void PutBufferAndCache(CachedBuffer** owner);
|
|
|
|
virtual void PutBuffer(CachedBuffer** owner);
|
|
|
|
|
|
|
|
virtual bool Lock() = 0;
|
|
|
|
virtual void Unlock() = 0;
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef DoublyLinkedList<CachedBuffer> BufferList;
|
|
|
|
|
|
|
|
private:
|
|
|
|
CachedBuffer* _AllocateBuffer(size_t size,
|
|
|
|
CachedBuffer** owner, bool* _newBuffer);
|
|
|
|
// object must not be locked
|
|
|
|
|
|
|
|
private:
|
|
|
|
size_t fBlockSize;
|
|
|
|
uint32 fMaxCachedBlocks;
|
|
|
|
uint32 fAllocatedBlocks;
|
|
|
|
BufferList fUnusedBuffers;
|
|
|
|
BufferList fCachedBuffers;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class BlockBufferCacheNoLock : public BlockBufferCache {
|
|
|
|
public:
|
|
|
|
BlockBufferCacheNoLock(size_t blockSize,
|
|
|
|
uint32 maxCachedBlocks);
|
|
|
|
virtual ~BlockBufferCacheNoLock();
|
|
|
|
|
|
|
|
virtual bool Lock();
|
|
|
|
virtual void Unlock();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-01-27 23:17:03 +00:00
|
|
|
} // namespace BPrivate
|
|
|
|
|
|
|
|
} // namespace BHaikuPackage
|
|
|
|
|
|
|
|
} // namespace BPackageKit
|
|
|
|
|
|
|
|
|
|
|
|
#endif // _PACKAGE__HPKG__BLOCK_BUFFER_CACHE_H_
|