mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-07-30 06:58:08 +03:00
Make the mutex n_waiting_thds field a C11-style atomic
This commit is contained in:
parent
492a941f49
commit
5dcc13b342
4 changed files with 19 additions and 7 deletions
|
|
@ -93,10 +93,11 @@ label_spin_done:
|
|||
/* Copy before to after to avoid clock skews. */
|
||||
nstime_t after;
|
||||
nstime_copy(&after, &before);
|
||||
uint32_t n_thds = atomic_add_u32(&data->n_waiting_thds, 1);
|
||||
uint32_t n_thds = atomic_fetch_add_u32(&data->n_waiting_thds, 1,
|
||||
ATOMIC_RELAXED) + 1;
|
||||
/* One last try as above two calls may take quite some cycles. */
|
||||
if (!malloc_mutex_trylock(mutex)) {
|
||||
atomic_sub_u32(&data->n_waiting_thds, 1);
|
||||
atomic_fetch_sub_u32(&data->n_waiting_thds, 1, ATOMIC_RELAXED);
|
||||
data->n_spin_acquired++;
|
||||
return;
|
||||
}
|
||||
|
|
@ -104,7 +105,7 @@ label_spin_done:
|
|||
/* True slow path. */
|
||||
malloc_mutex_lock_final(mutex);
|
||||
/* Update more slow-path only counters. */
|
||||
atomic_sub_u32(&data->n_waiting_thds, 1);
|
||||
atomic_fetch_sub_u32(&data->n_waiting_thds, 1, ATOMIC_RELAXED);
|
||||
nstime_update(&after);
|
||||
|
||||
nstime_t delta;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue