Changeset View
Changeset View
Standalone View
Standalone View
head/contrib/jemalloc/src/mutex.c
Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | return (((int (*)(pthread_mutex_t *, void *(*)(size_t, size_t))) | ||||
__libc_interposing[INTERPOS__pthread_mutex_init_calloc_cb])(mutex, | __libc_interposing[INTERPOS__pthread_mutex_init_calloc_cb])(mutex, | ||||
calloc_cb)); | calloc_cb)); | ||||
} | } | ||||
#endif | #endif | ||||
void | void | ||||
malloc_mutex_lock_slow(malloc_mutex_t *mutex) { | malloc_mutex_lock_slow(malloc_mutex_t *mutex) { | ||||
mutex_prof_data_t *data = &mutex->prof_data; | mutex_prof_data_t *data = &mutex->prof_data; | ||||
UNUSED nstime_t before = NSTIME_ZERO_INITIALIZER; | nstime_t before = NSTIME_ZERO_INITIALIZER; | ||||
if (ncpus == 1) { | if (ncpus == 1) { | ||||
goto label_spin_done; | goto label_spin_done; | ||||
} | } | ||||
int cnt = 0, max_cnt = MALLOC_MUTEX_MAX_SPIN; | int cnt = 0, max_cnt = MALLOC_MUTEX_MAX_SPIN; | ||||
do { | do { | ||||
spin_cpu_spinwait(); | spin_cpu_spinwait(); | ||||
if (!malloc_mutex_trylock_final(mutex)) { | if (!atomic_load_b(&mutex->locked, ATOMIC_RELAXED) | ||||
&& !malloc_mutex_trylock_final(mutex)) { | |||||
data->n_spin_acquired++; | data->n_spin_acquired++; | ||||
return; | return; | ||||
} | } | ||||
} while (cnt++ < max_cnt); | } while (cnt++ < max_cnt); | ||||
if (!config_stats) { | if (!config_stats) { | ||||
/* Only spin is useful when stats is off. */ | /* Only spin is useful when stats is off. */ | ||||
malloc_mutex_lock_final(mutex); | malloc_mutex_lock_final(mutex); | ||||
▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | # if _WIN32_WINNT >= 0x0600 | ||||
InitializeSRWLock(&mutex->lock); | InitializeSRWLock(&mutex->lock); | ||||
# else | # else | ||||
if (!InitializeCriticalSectionAndSpinCount(&mutex->lock, | if (!InitializeCriticalSectionAndSpinCount(&mutex->lock, | ||||
_CRT_SPINCOUNT)) { | _CRT_SPINCOUNT)) { | ||||
return true; | return true; | ||||
} | } | ||||
# endif | # endif | ||||
#elif (defined(JEMALLOC_OS_UNFAIR_LOCK)) | #elif (defined(JEMALLOC_OS_UNFAIR_LOCK)) | ||||
mutex->lock = OS_UNFAIR_LOCK_INIT; | mutex->lock = OS_UNFAIR_LOCK_INIT; | ||||
#elif (defined(JEMALLOC_OSSPIN)) | |||||
mutex->lock = 0; | |||||
#elif (defined(JEMALLOC_MUTEX_INIT_CB)) | #elif (defined(JEMALLOC_MUTEX_INIT_CB)) | ||||
if (postpone_init) { | if (postpone_init) { | ||||
mutex->postponed_next = postponed_mutexes; | mutex->postponed_next = postponed_mutexes; | ||||
postponed_mutexes = mutex; | postponed_mutexes = mutex; | ||||
} else { | } else { | ||||
if (_pthread_mutex_init_calloc_cb(&mutex->lock, | if (_pthread_mutex_init_calloc_cb(&mutex->lock, | ||||
bootstrap_calloc) != 0) { | bootstrap_calloc) != 0) { | ||||
return true; | return true; | ||||
▲ Show 20 Lines • Show All 67 Lines • Show Last 20 Lines |