Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/oneapi/tbb/tbb_allocator.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     Copyright (c) 2005-2021 Intel Corporation
0003 
0004     Licensed under the Apache License, Version 2.0 (the "License");
0005     you may not use this file except in compliance with the License.
0006     You may obtain a copy of the License at
0007 
0008         http://www.apache.org/licenses/LICENSE-2.0
0009 
0010     Unless required by applicable law or agreed to in writing, software
0011     distributed under the License is distributed on an "AS IS" BASIS,
0012     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013     See the License for the specific language governing permissions and
0014     limitations under the License.
0015 */
0016 
0017 #ifndef __TBB_tbb_allocator_H
0018 #define __TBB_tbb_allocator_H
0019 
0020 #include "oneapi/tbb/detail/_utils.h"
0021 #include "detail/_namespace_injection.h"
0022 #include <cstdlib>
0023 #include <utility>
0024 
0025 #if __TBB_CPP17_MEMORY_RESOURCE_PRESENT
0026 #include <memory_resource>
0027 #endif
0028 
0029 namespace tbb {
0030 namespace detail {
0031 
0032 namespace r1 {
0033 TBB_EXPORT void* __TBB_EXPORTED_FUNC allocate_memory(std::size_t size);
0034 TBB_EXPORT void  __TBB_EXPORTED_FUNC deallocate_memory(void* p);
0035 TBB_EXPORT bool  __TBB_EXPORTED_FUNC is_tbbmalloc_used();
0036 }
0037 
0038 namespace d1 {
0039 
0040 template<typename T>
0041 class tbb_allocator {
0042 public:
0043     using value_type = T;
0044     using propagate_on_container_move_assignment = std::true_type;
0045 
0046     //! Always defined for TBB containers (supported since C++17 for std containers)
0047     using is_always_equal = std::true_type;
0048 
0049     //! Specifies current allocator
0050     enum malloc_type {
0051         scalable,
0052         standard
0053     };
0054 
0055     tbb_allocator() = default;
0056     template<typename U> tbb_allocator(const tbb_allocator<U>&) noexcept {}
0057 
0058     //! Allocate space for n objects.
0059     __TBB_nodiscard T* allocate(std::size_t n) {
0060         return static_cast<T*>(r1::allocate_memory(n * sizeof(value_type)));
0061     }
0062 
0063     //! Free previously allocated block of memory.
0064     void deallocate(T* p, std::size_t) {
0065         r1::deallocate_memory(p);
0066     }
0067 
0068     //! Returns current allocator
0069     static malloc_type allocator_type() {
0070         return r1::is_tbbmalloc_used() ? standard : scalable;
0071     }
0072 
0073 #if TBB_ALLOCATOR_TRAITS_BROKEN
0074     using pointer = value_type*;
0075     using const_pointer = const value_type*;
0076     using reference = value_type&;
0077     using const_reference = const value_type&;
0078     using difference_type = std::ptrdiff_t;
0079     using size_type = std::size_t;
0080     template<typename U> struct rebind {
0081         using other = tbb_allocator<U>;
0082     };
0083     //! Largest value for which method allocate might succeed.
0084     size_type max_size() const noexcept {
0085         size_type max = ~(std::size_t(0)) / sizeof(value_type);
0086         return (max > 0 ? max : 1);
0087     }
0088     template<typename U, typename... Args>
0089     void construct(U *p, Args&&... args)
0090         { ::new (p) U(std::forward<Args>(args)...); }
0091     void destroy( pointer p ) { p->~value_type(); }
0092     pointer address(reference x) const { return &x; }
0093     const_pointer address(const_reference x) const { return &x; }
0094 #endif // TBB_ALLOCATOR_TRAITS_BROKEN
0095 };
0096 
0097 #if TBB_ALLOCATOR_TRAITS_BROKEN
0098     template<>
0099     class tbb_allocator<void> {
0100     public:
0101         using pointer = void*;
0102         using const_pointer = const void*;
0103         using value_type = void;
0104         template<typename U> struct rebind {
0105             using other = tbb_allocator<U>;
0106         };
0107     };
0108 #endif
0109 
0110 template<typename T, typename U>
0111 inline bool operator==(const tbb_allocator<T>&, const tbb_allocator<U>&) noexcept { return true; }
0112 
0113 #if !__TBB_CPP20_COMPARISONS_PRESENT
0114 template<typename T, typename U>
0115 inline bool operator!=(const tbb_allocator<T>&, const tbb_allocator<U>&) noexcept { return false; }
0116 #endif
0117 
0118 } // namespace d1
0119 } // namespace detail
0120 
0121 inline namespace v1 {
0122 using detail::d1::tbb_allocator;
0123 } // namespace v1
0124 } // namespace tbb
0125 
0126 #endif /* __TBB_tbb_allocator_H */