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