Initialize auto tcache (embedded in TSD). */
| 407 | |
| 408 | /* Initialize auto tcache (embedded in TSD). */ |
| 409 | static void |
| 410 | tcache_init(tsd_t *tsd, tcache_t *tcache, void *avail_stack) { |
| 411 | memset(&tcache->link, 0, sizeof(ql_elm(tcache_t))); |
| 412 | tcache->prof_accumbytes = 0; |
| 413 | tcache->next_gc_bin = 0; |
| 414 | tcache->arena = NULL; |
| 415 | |
| 416 | ticker_init(&tcache->gc_ticker, TCACHE_GC_INCR); |
| 417 | |
| 418 | size_t stack_offset = 0; |
| 419 | assert((TCACHE_NSLOTS_SMALL_MAX & 1U) == 0); |
| 420 | memset(tcache->bins_small, 0, sizeof(cache_bin_t) * SC_NBINS); |
| 421 | memset(tcache->bins_large, 0, sizeof(cache_bin_t) * (nhbins - SC_NBINS)); |
| 422 | unsigned i = 0; |
| 423 | for (; i < SC_NBINS; i++) { |
| 424 | tcache->lg_fill_div[i] = 1; |
| 425 | stack_offset += tcache_bin_info[i].ncached_max * sizeof(void *); |
| 426 | /* |
| 427 | * avail points past the available space. Allocations will |
| 428 | * access the slots toward higher addresses (for the benefit of |
| 429 | * prefetch). |
| 430 | */ |
| 431 | tcache_small_bin_get(tcache, i)->avail = |
| 432 | (void **)((uintptr_t)avail_stack + (uintptr_t)stack_offset); |
| 433 | } |
| 434 | for (; i < nhbins; i++) { |
| 435 | stack_offset += tcache_bin_info[i].ncached_max * sizeof(void *); |
| 436 | tcache_large_bin_get(tcache, i)->avail = |
| 437 | (void **)((uintptr_t)avail_stack + (uintptr_t)stack_offset); |
| 438 | } |
| 439 | assert(stack_offset == stack_nelms * sizeof(void *)); |
| 440 | } |
| 441 | |
| 442 | /* Initialize auto tcache (embedded in TSD). */ |
| 443 | bool |
no test coverage detected