2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
11 #ifndef WEBRTC_MODULES_AUDIO_CONFERENCE_MIXER_SOURCE_MEMORY_POOL_H_
12 #define WEBRTC_MODULES_AUDIO_CONFERENCE_MIXER_SOURCE_MEMORY_POOL_H_
16 #include "webrtc/typedefs.h"
19 #include "webrtc/modules/audio_conference_mixer/source/memory_pool_win.h"
21 #include "webrtc/modules/audio_conference_mixer/source/memory_pool_posix.h"
26 template<class MemoryType>
30 // Factory method, constructor disabled.
31 static int32_t CreateMemoryPool(MemoryPool*& memoryPool,
32 uint32_t initialPoolSize);
34 // Try to delete the memory pool. Fail with return value -1 if there is
35 // outstanding memory.
36 static int32_t DeleteMemoryPool(
37 MemoryPool*& memoryPool);
39 // Get/return unused memory.
40 int32_t PopMemory(MemoryType*& memory);
41 int32_t PushMemory(MemoryType*& memory);
43 MemoryPool(int32_t initialPoolSize);
46 MemoryPoolImpl<MemoryType>* _ptrImpl;
49 template<class MemoryType>
50 MemoryPool<MemoryType>::MemoryPool(int32_t initialPoolSize)
52 _ptrImpl = new MemoryPoolImpl<MemoryType>(initialPoolSize);
55 template<class MemoryType>
56 MemoryPool<MemoryType>::~MemoryPool()
61 template<class MemoryType> int32_t
62 MemoryPool<MemoryType>::CreateMemoryPool(MemoryPool*& memoryPool,
63 uint32_t initialPoolSize)
65 memoryPool = new MemoryPool(initialPoolSize);
66 if(memoryPool == NULL)
70 if(memoryPool->_ptrImpl == NULL)
76 if(!memoryPool->_ptrImpl->Initialize())
85 template<class MemoryType>
86 int32_t MemoryPool<MemoryType>::DeleteMemoryPool(MemoryPool*& memoryPool)
88 if(memoryPool == NULL)
92 if(memoryPool->_ptrImpl == NULL)
96 if(memoryPool->_ptrImpl->Terminate() == -1)
105 template<class MemoryType>
106 int32_t MemoryPool<MemoryType>::PopMemory(MemoryType*& memory)
108 return _ptrImpl->PopMemory(memory);
111 template<class MemoryType>
112 int32_t MemoryPool<MemoryType>::PushMemory(MemoryType*& memory)
118 return _ptrImpl->PushMemory(memory);
120 } // namespace webrtc
122 #endif // WEBRTC_MODULES_AUDIO_CONFERENCE_MIXER_SOURCE_MEMORY_POOL_H_