1 /*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef CHRE_UTIL_SYSTEM_SYNCHRONIZED_MEMORY_POOL_IMPL_H_
18 #define CHRE_UTIL_SYSTEM_SYNCHRONIZED_MEMORY_POOL_IMPL_H_
19
20 // IWYU pragma: private
21 #include "chre/util/lock_guard.h"
22 #include "chre/util/system/synchronized_memory_pool.h"
23
24 namespace chre {
25
26 template <typename ElementType, size_t kSize>
27 template <typename... Args>
allocate(Args &&...args)28 ElementType *SynchronizedMemoryPool<ElementType, kSize>::allocate(
29 Args &&...args) {
30 LockGuard<Mutex> lock(mMutex);
31 return mMemoryPool.allocate(args...);
32 }
33
34 template <typename ElementType, size_t kSize>
deallocate(ElementType * element)35 void SynchronizedMemoryPool<ElementType, kSize>::deallocate(
36 ElementType *element) {
37 LockGuard<Mutex> lock(mMutex);
38 mMemoryPool.deallocate(element);
39 }
40
41 template <typename ElementType, size_t kSize>
find(MatchingFunction * matchingFunction,void * data)42 ElementType *SynchronizedMemoryPool<ElementType, kSize>::find(
43 MatchingFunction *matchingFunction, void *data) {
44 LockGuard<Mutex> lock(mMutex);
45 return mMemoryPool.find(matchingFunction, data);
46 }
47
48 template <typename ElementType, size_t kSize>
getFreeBlockCount()49 size_t SynchronizedMemoryPool<ElementType, kSize>::getFreeBlockCount() {
50 LockGuard<Mutex> lock(mMutex);
51 return mMemoryPool.getFreeBlockCount();
52 }
53
54 } // namespace chre
55
56 #endif // CHRE_UTIL_SYSTEM_SYNCHRONIZED_MEMORY_POOL_IMPL_H_
57