Convert accumbytes in prof_accum_t to C11 atomics, when possible
This commit is contained in:
parent
55d992c48c
commit
30d74db08e
@ -22,15 +22,16 @@ prof_accum_add(tsdn_t *tsdn, prof_accum_t *prof_accum, uint64_t accumbytes) {
|
|||||||
* avoids rate-limiting allocation.
|
* avoids rate-limiting allocation.
|
||||||
*/
|
*/
|
||||||
#ifdef JEMALLOC_ATOMIC_U64
|
#ifdef JEMALLOC_ATOMIC_U64
|
||||||
|
a0 = atomic_load_u64(&prof_accum->accumbytes, ATOMIC_RELAXED);
|
||||||
do {
|
do {
|
||||||
a0 = atomic_read_u64(&prof_accum->accumbytes);
|
|
||||||
a1 = a0 + accumbytes;
|
a1 = a0 + accumbytes;
|
||||||
assert(a1 >= a0);
|
assert(a1 >= a0);
|
||||||
overflow = (a1 >= prof_interval);
|
overflow = (a1 >= prof_interval);
|
||||||
if (overflow) {
|
if (overflow) {
|
||||||
a1 %= prof_interval;
|
a1 %= prof_interval;
|
||||||
}
|
}
|
||||||
} while (atomic_cas_u64(&prof_accum->accumbytes, a0, a1));
|
} while (!atomic_compare_exchange_weak_u64(&prof_accum->accumbytes, &a0,
|
||||||
|
a1, ATOMIC_RELAXED, ATOMIC_RELAXED));
|
||||||
#else
|
#else
|
||||||
malloc_mutex_lock(tsdn, &prof_accum->mtx);
|
malloc_mutex_lock(tsdn, &prof_accum->mtx);
|
||||||
a0 = prof_accum->accumbytes;
|
a0 = prof_accum->accumbytes;
|
||||||
@ -57,11 +58,12 @@ prof_accum_cancel(tsdn_t *tsdn, prof_accum_t *prof_accum, size_t usize) {
|
|||||||
*/
|
*/
|
||||||
uint64_t a0, a1;
|
uint64_t a0, a1;
|
||||||
#ifdef JEMALLOC_ATOMIC_U64
|
#ifdef JEMALLOC_ATOMIC_U64
|
||||||
|
a0 = atomic_load_u64(&prof_accum->accumbytes, ATOMIC_RELAXED);
|
||||||
do {
|
do {
|
||||||
a0 = atomic_read_u64(&prof_accum->accumbytes);
|
|
||||||
a1 = (a0 >= LARGE_MINCLASS - usize) ? a0 - (LARGE_MINCLASS -
|
a1 = (a0 >= LARGE_MINCLASS - usize) ? a0 - (LARGE_MINCLASS -
|
||||||
usize) : 0;
|
usize) : 0;
|
||||||
} while (atomic_cas_u64(&prof_accum->accumbytes, a0, a1));
|
} while (!atomic_compare_exchange_weak_u64(&prof_accum->accumbytes, &a0,
|
||||||
|
a1, ATOMIC_RELAXED, ATOMIC_RELAXED));
|
||||||
#else
|
#else
|
||||||
malloc_mutex_lock(tsdn, &prof_accum->mtx);
|
malloc_mutex_lock(tsdn, &prof_accum->mtx);
|
||||||
a0 = prof_accum->accumbytes;
|
a0 = prof_accum->accumbytes;
|
||||||
|
@ -18,8 +18,10 @@ typedef struct {
|
|||||||
struct prof_accum_s {
|
struct prof_accum_s {
|
||||||
#ifndef JEMALLOC_ATOMIC_U64
|
#ifndef JEMALLOC_ATOMIC_U64
|
||||||
malloc_mutex_t mtx;
|
malloc_mutex_t mtx;
|
||||||
#endif
|
|
||||||
uint64_t accumbytes;
|
uint64_t accumbytes;
|
||||||
|
#else
|
||||||
|
atomic_u64_t accumbytes;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
struct prof_cnt_s {
|
struct prof_cnt_s {
|
||||||
|
@ -1758,8 +1758,10 @@ prof_accum_init(tsdn_t *tsdn, prof_accum_t *prof_accum) {
|
|||||||
WITNESS_RANK_PROF_ACCUM)) {
|
WITNESS_RANK_PROF_ACCUM)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
prof_accum->accumbytes = 0;
|
prof_accum->accumbytes = 0;
|
||||||
|
#else
|
||||||
|
atomic_store_u64(&prof_accum->accumbytes, 0, ATOMIC_RELAXED);
|
||||||
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user