mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-05-26 14:56:23 +03:00
Mutex: Make spin count configurable.
Don't document it since we don't want to support this as a "real" setting, but it's handy for testing.
This commit is contained in:
parent
dae24589bc
commit
6f41ba55ee
5 changed files with 18 additions and 9 deletions
10
src/mutex.c
10
src/mutex.c
|
|
@ -9,6 +9,12 @@
|
|||
#define _CRT_SPINCOUNT 4000
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Based on benchmark results, a fixed spin with this amount of retries works
|
||||
* well for our critical sections.
|
||||
*/
|
||||
int64_t opt_mutex_max_spin = 250;
|
||||
|
||||
/******************************************************************************/
|
||||
/* Data. */
|
||||
|
||||
|
|
@ -51,7 +57,7 @@ malloc_mutex_lock_slow(malloc_mutex_t *mutex) {
|
|||
goto label_spin_done;
|
||||
}
|
||||
|
||||
int cnt = 0, max_cnt = MALLOC_MUTEX_MAX_SPIN;
|
||||
int cnt = 0;
|
||||
do {
|
||||
spin_cpu_spinwait();
|
||||
if (!atomic_load_b(&mutex->locked, ATOMIC_RELAXED)
|
||||
|
|
@ -59,7 +65,7 @@ malloc_mutex_lock_slow(malloc_mutex_t *mutex) {
|
|||
data->n_spin_acquired++;
|
||||
return;
|
||||
}
|
||||
} while (cnt++ < max_cnt);
|
||||
} while (cnt++ < opt_mutex_max_spin || opt_mutex_max_spin == -1);
|
||||
|
||||
if (!config_stats) {
|
||||
/* Only spin is useful when stats is off. */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue