1 /*
2 * Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de>
3 * Distributed under the terms of the MIT License.
4 */
5
6
7 #include <package/hpkg/BlockBufferPool.h>
8
9 #include <new>
10
11 #include <package/hpkg/BlockBufferPoolImpl.h>
12
13
14 namespace BPackageKit {
15
16 namespace BHPKG {
17
18
BBlockBufferPool(size_t blockSize,uint32 maxCachedBlocks)19 BBlockBufferPool::BBlockBufferPool(size_t blockSize, uint32 maxCachedBlocks)
20 :
21 fImpl(new (std::nothrow) BlockBufferPoolImpl(blockSize, maxCachedBlocks,
22 this))
23 {
24 }
25
26
~BBlockBufferPool()27 BBlockBufferPool::~BBlockBufferPool()
28 {
29 delete fImpl;
30 }
31
32
33 status_t
Init()34 BBlockBufferPool::Init()
35 {
36 if (fImpl == NULL)
37 return B_NO_MEMORY;
38
39 return fImpl->Init();
40 }
41
42
43 PoolBuffer*
GetBuffer(size_t size,PoolBuffer ** owner,bool * _newBuffer)44 BBlockBufferPool::GetBuffer(size_t size, PoolBuffer** owner,
45 bool* _newBuffer)
46 {
47 if (fImpl == NULL)
48 return NULL;
49
50 return fImpl->GetBuffer(size, owner, _newBuffer);
51 }
52
53
54 void
PutBufferAndCache(PoolBuffer ** owner)55 BBlockBufferPool::PutBufferAndCache(PoolBuffer** owner)
56 {
57 if (fImpl != NULL)
58 fImpl->PutBufferAndCache(owner);
59 }
60
61
62 void
PutBuffer(PoolBuffer ** owner)63 BBlockBufferPool::PutBuffer(PoolBuffer** owner)
64 {
65 if (fImpl != NULL)
66 fImpl->PutBuffer(owner);
67 }
68
69
70 } // namespace BHPKG
71
72 } // namespace BPackageKit
73