| 132 | } |
| 133 | |
| 134 | bool |
| 135 | malloc_mutex_init(malloc_mutex_t *mutex, const char *name, |
| 136 | witness_rank_t rank, malloc_mutex_lock_order_t lock_order) { |
| 137 | mutex_prof_data_init(&mutex->prof_data); |
| 138 | #ifdef _WIN32 |
| 139 | # if _WIN32_WINNT >= 0x0600 |
| 140 | InitializeSRWLock(&mutex->lock); |
| 141 | # else |
| 142 | if (!InitializeCriticalSectionAndSpinCount(&mutex->lock, |
| 143 | _CRT_SPINCOUNT)) { |
| 144 | return true; |
| 145 | } |
| 146 | # endif |
| 147 | #elif (defined(JEMALLOC_OS_UNFAIR_LOCK)) |
| 148 | mutex->lock = OS_UNFAIR_LOCK_INIT; |
| 149 | #elif (defined(JEMALLOC_MUTEX_INIT_CB)) |
| 150 | if (postpone_init) { |
| 151 | mutex->postponed_next = postponed_mutexes; |
| 152 | postponed_mutexes = mutex; |
| 153 | } else { |
| 154 | if (_pthread_mutex_init_calloc_cb(&mutex->lock, |
| 155 | bootstrap_calloc) != 0) { |
| 156 | return true; |
| 157 | } |
| 158 | } |
| 159 | #else |
| 160 | pthread_mutexattr_t attr; |
| 161 | |
| 162 | if (pthread_mutexattr_init(&attr) != 0) { |
| 163 | return true; |
| 164 | } |
| 165 | pthread_mutexattr_settype(&attr, MALLOC_MUTEX_TYPE); |
| 166 | if (pthread_mutex_init(&mutex->lock, &attr) != 0) { |
| 167 | pthread_mutexattr_destroy(&attr); |
| 168 | return true; |
| 169 | } |
| 170 | pthread_mutexattr_destroy(&attr); |
| 171 | #endif |
| 172 | if (config_debug) { |
| 173 | mutex->lock_order = lock_order; |
| 174 | if (lock_order == malloc_mutex_address_ordered) { |
| 175 | witness_init(&mutex->witness, name, rank, |
| 176 | mutex_addr_comp, mutex); |
| 177 | } else { |
| 178 | witness_init(&mutex->witness, name, rank, NULL, NULL); |
| 179 | } |
| 180 | } |
| 181 | return false; |
| 182 | } |
| 183 | |
| 184 | void |
| 185 | malloc_mutex_prefork(tsdn_t *tsdn, malloc_mutex_t *mutex) { |
no test coverage detected