Intel(R) Threading Building Blocks Doxygen Documentation
version 4.2.3
|
Go to the documentation of this file.
17 #ifndef __TBB_cache_aligned_allocator_H
18 #define __TBB_cache_aligned_allocator_H
22 #if __TBB_ALLOCATOR_CONSTRUCT_VARIADIC
26 #if __TBB_CPP17_MEMORY_RESOURCE_PRESENT
27 #include <memory_resource>
49 #if _MSC_VER && !defined(__INTEL_COMPILER)
51 #pragma warning (push)
52 #pragma warning (disable: 4100)
96 #if __TBB_ALLOCATOR_CONSTRUCT_VARIADIC
97 template<
typename U,
typename... Args>
99 { ::new((
void *)
p) U(std::forward<Args>(args)...); }
100 #else // __TBB_ALLOCATOR_CONSTRUCT_VARIADIC
101 #if __TBB_CPP11_RVALUE_REF_PRESENT
105 #endif // __TBB_ALLOCATOR_CONSTRUCT_VARIADIC
111 #if _MSC_VER && !defined(__INTEL_COMPILER)
112 #pragma warning (pop)
113 #endif // warning 4100 is back
123 template<
typename U>
struct rebind {
128 template<
typename T,
typename U>
131 template<
typename T,
typename U>
134 #if __TBB_CPP17_MEMORY_RESOURCE_PRESENT
137 class cache_aligned_resource :
public std::pmr::memory_resource {
139 cache_aligned_resource() : cache_aligned_resource(std::pmr::get_default_resource()) {}
140 explicit cache_aligned_resource(std::pmr::memory_resource* upstream) : m_upstream(upstream) {}
142 std::pmr::memory_resource* upstream_resource()
const {
148 void* do_allocate(
size_t bytes,
size_t alignment)
override {
149 size_t cache_line_alignment = correct_alignment(alignment);
150 uintptr_t base = (uintptr_t)m_upstream->allocate(correct_size(bytes) + cache_line_alignment);
151 __TBB_ASSERT(base != 0,
"Upstream resource returned NULL.");
152 #if _MSC_VER && !defined(__INTEL_COMPILER)
154 #pragma warning(push)
155 #pragma warning(disable: 4146 4706)
158 uintptr_t result = (base + cache_line_alignment) & -cache_line_alignment;
159 #if _MSC_VER && !defined(__INTEL_COMPILER)
163 ((uintptr_t*)result)[-1] = base;
164 return (
void*)result;
167 void do_deallocate(
void* ptr,
size_t bytes,
size_t alignment)
override {
170 uintptr_t base = ((uintptr_t*)ptr)[-1];
171 m_upstream->deallocate((
void*)base, correct_size(bytes) + correct_alignment(alignment));
175 bool do_is_equal(
const std::pmr::memory_resource& other)
const noexcept
override {
176 if (
this == &other) {
return true; }
177 #if __TBB_USE_OPTIONAL_RTTI
178 const cache_aligned_resource* other_res =
dynamic_cast<const cache_aligned_resource*
>(&other);
179 return other_res && (this->upstream_resource() == other_res->upstream_resource());
185 size_t correct_alignment(
size_t alignment) {
187 #if __TBB_CPP17_HW_INTERFERENCE_SIZE_PRESENT
195 size_t correct_size(
size_t bytes) {
198 return bytes <
sizeof(uintptr_t) ?
sizeof(uintptr_t) : bytes;
201 std::pmr::memory_resource* m_upstream;
ptrdiff_t difference_type
pointer address(reference x) const
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
const typedef void * const_pointer
cache_aligned_allocator(const cache_aligned_allocator< U > &)
static const size_t cache_line_size
Meets "allocator" requirements of ISO C++ Standard, Section 20.1.5.
void deallocate(pointer p, size_type)
Free block of memory that starts on a cache line.
bool operator!=(const cache_aligned_allocator< T > &, const cache_aligned_allocator< U > &)
bool is_power_of_two(integer_type arg)
A function to check if passed integer is a power of 2.
cache_aligned_allocator< U > other
void destroy(pointer p)
Destroy value at location pointed to by p.
internal::allocator_type< T >::value_type value_type
void construct(pointer p, value_type &&value)
Copy-construct value at location pointed to by p.
bool operator==(const cache_aligned_allocator< T > &, const cache_aligned_allocator< U > &)
const typedef value_type & const_reference
void move(tbb_thread &t1, tbb_thread &t2)
cache_aligned_allocator()
void construct(pointer p, const value_type &value)
const_pointer address(const_reference x) const
const size_t NFS_MaxLineSize
Compile-time constant that is upper bound on cache line/sector size.
#define __TBB_EXPORTED_FUNC
cache_aligned_allocator< U > other
size_t __TBB_EXPORTED_FUNC NFS_GetLineSize()
Cache/sector line size.
pointer allocate(size_type n, const void *hint=0)
Allocate space for n objects, starting on a cache/sector line.
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long value
void const char const char int ITT_FORMAT __itt_group_sync p
const typedef value_type * const_pointer
void __TBB_EXPORTED_FUNC NFS_Free(void *)
Free memory allocated by NFS_Allocate.
size_type max_size() const
Largest value for which method allocate might succeed.
cache_aligned_allocator(const cache_aligned_allocator &)
void *__TBB_EXPORTED_FUNC NFS_Allocate(size_t n_element, size_t element_size, void *hint)
Allocate memory on cache/sector line boundary.
Copyright © 2005-2020 Intel Corporation. All Rights Reserved.
Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are
registered trademarks or trademarks of Intel Corporation or its
subsidiaries in the United States and other countries.
* Other names and brands may be claimed as the property of others.