| 297 | } |
| 298 | |
| 299 | static void * |
| 300 | base_alloc_impl(tsdn_t *tsdn, base_t *base, size_t size, size_t alignment, |
| 301 | size_t *esn) { |
| 302 | alignment = QUANTUM_CEILING(alignment); |
| 303 | size_t usize = ALIGNMENT_CEILING(size, alignment); |
| 304 | size_t asize = usize + alignment - QUANTUM; |
| 305 | |
| 306 | extent_t *extent = NULL; |
| 307 | malloc_mutex_lock(tsdn, &base->mtx); |
| 308 | for (szind_t i = sz_size2index(asize); i < NSIZES; i++) { |
| 309 | extent = extent_heap_remove_first(&base->avail[i]); |
| 310 | if (extent != NULL) { |
| 311 | /* Use existing space. */ |
| 312 | break; |
| 313 | } |
| 314 | } |
| 315 | if (extent == NULL) { |
| 316 | /* Try to allocate more space. */ |
| 317 | extent = base_extent_alloc(tsdn, base, usize, alignment); |
| 318 | } |
| 319 | void *ret; |
| 320 | if (extent == NULL) { |
| 321 | ret = NULL; |
| 322 | goto label_return; |
| 323 | } |
| 324 | |
| 325 | ret = base_extent_bump_alloc(tsdn, base, extent, usize, alignment); |
| 326 | if (esn != NULL) { |
| 327 | *esn = extent_sn_get(extent); |
| 328 | } |
| 329 | label_return: |
| 330 | malloc_mutex_unlock(tsdn, &base->mtx); |
| 331 | return ret; |
| 332 | } |
| 333 | |
| 334 | /* |
| 335 | * base_alloc() returns zeroed memory, which is always demand-zeroed for the |
no test coverage detected