1 /*
2     Copyright (c) 2020-2021 Intel Corporation
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 __TBB_small_object_pool_impl_H
18 #define __TBB_small_object_pool_impl_H
19 
20 #include "oneapi/tbb/detail/_small_object_pool.h"
21 #include "oneapi/tbb/detail/_utils.h"
22 
23 #include <cstddef>
24 #include <cstdint>
25 #include <atomic>
26 
27 
28 namespace tbb {
29 namespace detail {
30 namespace r1 {
31 
32 class thread_data;
33 
34 class small_object_pool_impl : public d1::small_object_pool
35 {
36     static constexpr std::size_t small_object_size = 256;
37     struct small_object {
38         small_object* next;
39     };
40     static small_object* const dead_public_list;
41 public:
42     void* allocate_impl(small_object_pool*& allocator, std::size_t number_of_bytes);
43     void deallocate_impl(void* ptr, std::size_t number_of_bytes, thread_data& td);
44     void destroy();
45 private:
46     static std::int64_t cleanup_list(small_object* list);
47     ~small_object_pool_impl() = default;
48 private:
alignas(max_nfs_size)49     alignas(max_nfs_size) small_object* m_private_list;
50     std::int64_t m_private_counter{};
51     alignas(max_nfs_size) std::atomic<small_object*> m_public_list;
52     std::atomic<std::int64_t> m_public_counter{};
53 };
54 
55 } // namespace r1
56 } // namespace detail
57 } // namespace tbb
58 
59 #endif /* __TBB_small_object_pool_impl_H */
60