xref: /haiku/headers/private/package/hpkg/BlockBufferPoolImpl.h (revision 9f81ca838ce7b92b5689e57d3f86765db4705a7b)
1*0ee16518SIngo Weinhold /*
2*0ee16518SIngo Weinhold  * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3*0ee16518SIngo Weinhold  * Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de>
4*0ee16518SIngo Weinhold  * Distributed under the terms of the MIT License.
5*0ee16518SIngo Weinhold  */
6*0ee16518SIngo Weinhold #ifndef _PACKAGE__HPKG__PRIVATE__BLOCK_BUFFER_POOL_H_
7*0ee16518SIngo Weinhold #define _PACKAGE__HPKG__PRIVATE__BLOCK_BUFFER_POOL_H_
8*0ee16518SIngo Weinhold 
9*0ee16518SIngo Weinhold 
10*0ee16518SIngo Weinhold #include <SupportDefs.h>
11*0ee16518SIngo Weinhold 
12*0ee16518SIngo Weinhold #include <util/DoublyLinkedList.h>
13*0ee16518SIngo Weinhold 
14*0ee16518SIngo Weinhold #include <package/hpkg/BufferPool.h>
15*0ee16518SIngo Weinhold 
16*0ee16518SIngo Weinhold 
17*0ee16518SIngo Weinhold namespace BPackageKit {
18*0ee16518SIngo Weinhold 
19*0ee16518SIngo Weinhold namespace BHPKG {
20*0ee16518SIngo Weinhold 
21*0ee16518SIngo Weinhold namespace BPrivate {
22*0ee16518SIngo Weinhold 
23*0ee16518SIngo Weinhold 
24*0ee16518SIngo Weinhold class PoolBuffer;
25*0ee16518SIngo Weinhold 
26*0ee16518SIngo Weinhold 
27*0ee16518SIngo Weinhold class BlockBufferPoolImpl : public BBufferPool {
28*0ee16518SIngo Weinhold public:
29*0ee16518SIngo Weinhold 								BlockBufferPoolImpl(size_t blockSize,
30*0ee16518SIngo Weinhold 									uint32 maxCachedBlocks,
31*0ee16518SIngo Weinhold 									BBufferPoolLockable* lockable);
32*0ee16518SIngo Weinhold 								~BlockBufferPoolImpl();
33*0ee16518SIngo Weinhold 
34*0ee16518SIngo Weinhold 			status_t			Init();
35*0ee16518SIngo Weinhold 
36*0ee16518SIngo Weinhold 			PoolBuffer*			GetBuffer(size_t size,
37*0ee16518SIngo Weinhold 									PoolBuffer** owner = NULL,
38*0ee16518SIngo Weinhold 									bool* _newBuffer = NULL);
39*0ee16518SIngo Weinhold 			void				PutBufferAndCache(PoolBuffer** owner);
40*0ee16518SIngo Weinhold 			void				PutBuffer(PoolBuffer** owner);
41*0ee16518SIngo Weinhold 
42*0ee16518SIngo Weinhold private:
43*0ee16518SIngo Weinhold 			typedef DoublyLinkedList<PoolBuffer> BufferList;
44*0ee16518SIngo Weinhold 
45*0ee16518SIngo Weinhold private:
46*0ee16518SIngo Weinhold 			PoolBuffer*			_AllocateBuffer(size_t size,
47*0ee16518SIngo Weinhold 									PoolBuffer** owner, bool* _newBuffer);
48*0ee16518SIngo Weinhold 									// object must not be locked
49*0ee16518SIngo Weinhold 
50*0ee16518SIngo Weinhold private:
51*0ee16518SIngo Weinhold 			size_t				fBlockSize;
52*0ee16518SIngo Weinhold 			uint32				fMaxCachedBlocks;
53*0ee16518SIngo Weinhold 			uint32				fAllocatedBlocks;
54*0ee16518SIngo Weinhold 			BufferList			fUnusedBuffers;
55*0ee16518SIngo Weinhold 			BufferList			fCachedBuffers;
56*0ee16518SIngo Weinhold 			BBufferPoolLockable*	fLockable;
57*0ee16518SIngo Weinhold };
58*0ee16518SIngo Weinhold 
59*0ee16518SIngo Weinhold 
60*0ee16518SIngo Weinhold }	// namespace BPrivate
61*0ee16518SIngo Weinhold 
62*0ee16518SIngo Weinhold }	// namespace BHPKG
63*0ee16518SIngo Weinhold 
64*0ee16518SIngo Weinhold }	// namespace BPackageKit
65*0ee16518SIngo Weinhold 
66*0ee16518SIngo Weinhold 
67*0ee16518SIngo Weinhold #endif	// _PACKAGE__HPKG__PRIVATE__BLOCK_BUFFER_POOL_H_
68