MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / malloc_init_hard

Function malloc_init_hard

deps/jemalloc/src/jemalloc.c:1732–1802  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1730}
1731
1732static bool
1733malloc_init_hard(void) {
1734 tsd_t *tsd;
1735
1736#if defined(_WIN32) && _WIN32_WINNT < 0x0600
1737 _init_init_lock();
1738#endif
1739 malloc_mutex_lock(TSDN_NULL, &init_lock);
1740
1741#define UNLOCK_RETURN(tsdn, ret, reentrancy) \
1742 malloc_init_hard_cleanup(tsdn, reentrancy); \
1743 return ret;
1744
1745 if (!malloc_init_hard_needed()) {
1746 UNLOCK_RETURN(TSDN_NULL, false, false)
1747 }
1748
1749 if (malloc_init_state != malloc_init_a0_initialized &&
1750 malloc_init_hard_a0_locked()) {
1751 UNLOCK_RETURN(TSDN_NULL, true, false)
1752 }
1753
1754 malloc_mutex_unlock(TSDN_NULL, &init_lock);
1755 /* Recursive allocation relies on functional tsd. */
1756 tsd = malloc_tsd_boot0();
1757 if (tsd == NULL) {
1758 return true;
1759 }
1760 if (malloc_init_hard_recursible()) {
1761 return true;
1762 }
1763
1764 malloc_mutex_lock(tsd_tsdn(tsd), &init_lock);
1765 /* Set reentrancy level to 1 during init. */
1766 pre_reentrancy(tsd, NULL);
1767 /* Initialize narenas before prof_boot2 (for allocation). */
1768 if (malloc_init_narenas() || background_thread_boot1(tsd_tsdn(tsd))) {
1769 UNLOCK_RETURN(tsd_tsdn(tsd), true, true)
1770 }
1771 if (config_prof && prof_boot2(tsd)) {
1772 UNLOCK_RETURN(tsd_tsdn(tsd), true, true)
1773 }
1774
1775 malloc_init_percpu();
1776
1777 if (malloc_init_hard_finish()) {
1778 UNLOCK_RETURN(tsd_tsdn(tsd), true, true)
1779 }
1780 post_reentrancy(tsd);
1781 malloc_mutex_unlock(tsd_tsdn(tsd), &init_lock);
1782
1783 witness_assert_lockless(witness_tsd_tsdn(
1784 tsd_witness_tsdp_get_unsafe(tsd)));
1785 malloc_tsd_boot1();
1786 /* Update TSD after tsd_boot1. */
1787 tsd = tsd_fetch();
1788 if (opt_background_thread) {
1789 assert(have_background_thread);

Callers 1

malloc_initFunction · 0.70

Calls 15

_init_init_lockFunction · 0.70
malloc_init_hard_neededFunction · 0.70
malloc_tsd_boot0Function · 0.70
malloc_init_narenasFunction · 0.70
background_thread_boot1Function · 0.70
prof_boot2Function · 0.70
malloc_init_percpuFunction · 0.70
malloc_init_hard_finishFunction · 0.70
malloc_tsd_boot1Function · 0.70

Tested by

no test coverage detected