| 211 | } |
| 212 | |
| 213 | static void* std_cache_aligned_allocate(std::size_t bytes, std::size_t alignment) { |
| 214 | #if defined(__TBB_USE_MEMALIGN) |
| 215 | return memalign(alignment, bytes); |
| 216 | #elif defined(__TBB_USE_POSIX_MEMALIGN) |
| 217 | void* p = nullptr; |
| 218 | int res = posix_memalign(&p, alignment, bytes); |
| 219 | if (res != 0) |
| 220 | p = nullptr; |
| 221 | return p; |
| 222 | #elif defined(__TBB_USE_MSVC_ALIGNED_MALLOC) |
| 223 | return _aligned_malloc(bytes, alignment); |
| 224 | #else |
| 225 | // TODO: make it common with cache_aligned_resource |
| 226 | std::size_t space = alignment + bytes; |
| 227 | std::uintptr_t base = reinterpret_cast<std::uintptr_t>(std::malloc(space)); |
| 228 | if (!base) { |
| 229 | return nullptr; |
| 230 | } |
| 231 | std::uintptr_t result = (base + nfs_size) & ~(nfs_size - 1); |
| 232 | // Round up to the next cache line (align the base address) |
| 233 | __TBB_ASSERT((result - base) >= sizeof(std::uintptr_t), "Cannot store a base pointer to the header"); |
| 234 | __TBB_ASSERT(space - (result - base) >= bytes, "Not enough space for the storage"); |
| 235 | |
| 236 | // Record where block actually starts. |
| 237 | (reinterpret_cast<std::uintptr_t*>(result))[-1] = base; |
| 238 | return reinterpret_cast<void*>(result); |
| 239 | #endif |
| 240 | } |
| 241 | |
| 242 | static void std_cache_aligned_deallocate(void* p) { |
| 243 | #if defined(__TBB_USE_MEMALIGN) || defined(__TBB_USE_POSIX_MEMALIGN) |
nothing calls this directly
no test coverage detected