| 179 | #endif |
| 180 | |
| 181 | void* NFS_Allocate( size_t n, size_t element_size, void* /*hint*/ ) { |
| 182 | size_t m = NFS_LineSize; |
| 183 | __TBB_ASSERT( m<=NFS_MaxLineSize, "illegal value for NFS_LineSize" ); |
| 184 | __TBB_ASSERT( (m & (m-1))==0, "must be power of two" ); |
| 185 | size_t bytes = n*element_size; |
| 186 | |
| 187 | if (bytes<n || bytes+m<bytes) { |
| 188 | // Overflow |
| 189 | throw_exception(eid_bad_alloc); |
| 190 | } |
| 191 | // scalable_aligned_malloc considers zero size request an error, and returns NULL |
| 192 | if (bytes==0) bytes = 1; |
| 193 | |
| 194 | void* result = (*padded_allocate_handler)( bytes, m ); |
| 195 | if (!result) |
| 196 | throw_exception(eid_bad_alloc); |
| 197 | |
| 198 | __TBB_ASSERT( ((size_t)result&(m-1)) == 0, "The address returned isn't aligned to cache line size" ); |
| 199 | return result; |
| 200 | } |
| 201 | |
| 202 | void NFS_Free( void* p ) { |
| 203 | (*padded_free_handler)( p ); |
no test coverage detected