| 418 | } |
| 419 | |
| 420 | static void * |
| 421 | base_alloc_impl(tsdn_t *tsdn, base_t *base, size_t size, size_t alignment, |
| 422 | size_t *esn) { |
| 423 | alignment = QUANTUM_CEILING(alignment); |
| 424 | size_t usize = ALIGNMENT_CEILING(size, alignment); |
| 425 | size_t asize = usize + alignment - QUANTUM; |
| 426 | |
| 427 | extent_t *extent = NULL; |
| 428 | malloc_mutex_lock(tsdn, &base->mtx); |
| 429 | for (szind_t i = sz_size2index(asize); i < SC_NSIZES; i++) { |
| 430 | extent = extent_heap_remove_first(&base->avail[i]); |
| 431 | if (extent != NULL) { |
| 432 | /* Use existing space. */ |
| 433 | break; |
| 434 | } |
| 435 | } |
| 436 | if (extent == NULL) { |
| 437 | /* Try to allocate more space. */ |
| 438 | extent = base_extent_alloc(tsdn, base, usize, alignment); |
| 439 | } |
| 440 | void *ret; |
| 441 | if (extent == NULL) { |
| 442 | ret = NULL; |
| 443 | goto label_return; |
| 444 | } |
| 445 | |
| 446 | ret = base_extent_bump_alloc(base, extent, usize, alignment); |
| 447 | if (esn != NULL) { |
| 448 | *esn = extent_sn_get(extent); |
| 449 | } |
| 450 | label_return: |
| 451 | malloc_mutex_unlock(tsdn, &base->mtx); |
| 452 | return ret; |
| 453 | } |
| 454 | |
| 455 | /* |
| 456 | * base_alloc() returns zeroed memory, which is always demand-zeroed for the |
no test coverage detected