summaryrefslogtreecommitdiffstats
path: root/include/jemalloc
diff options
context:
space:
mode:
authorDavid Goldblatt <davidgoldblatt@fb.com>2017-04-05 01:08:58 (GMT)
committerDavid Goldblatt <davidtgoldblatt@gmail.com>2017-04-05 23:25:37 (GMT)
commit30d74db08ef2617236cbff219b5f40c9ff0aa0fc (patch)
tree09e65ab02a1f5364cd6d50f4847001d1bb3be2d1 /include/jemalloc
parent55d992c48c0ca9c5d823bd717f854c2c8939d1f3 (diff)
downloadjemalloc-30d74db08ef2617236cbff219b5f40c9ff0aa0fc.zip
jemalloc-30d74db08ef2617236cbff219b5f40c9ff0aa0fc.tar.gz
jemalloc-30d74db08ef2617236cbff219b5f40c9ff0aa0fc.tar.bz2
Convert accumbytes in prof_accum_t to C11 atomics, when possible
Diffstat (limited to 'include/jemalloc')
-rw-r--r--include/jemalloc/internal/prof_inlines_a.h10
-rw-r--r--include/jemalloc/internal/prof_structs.h4
2 files changed, 9 insertions, 5 deletions
diff --git a/include/jemalloc/internal/prof_inlines_a.h b/include/jemalloc/internal/prof_inlines_a.h
index d77635a..d0d2968 100644
--- a/include/jemalloc/internal/prof_inlines_a.h
+++ b/include/jemalloc/internal/prof_inlines_a.h
@@ -22,15 +22,16 @@ prof_accum_add(tsdn_t *tsdn, prof_accum_t *prof_accum, uint64_t accumbytes) {
* avoids rate-limiting allocation.
*/
#ifdef JEMALLOC_ATOMIC_U64
+ a0 = atomic_load_u64(&prof_accum->accumbytes, ATOMIC_RELAXED);
do {
- a0 = atomic_read_u64(&prof_accum->accumbytes);
a1 = a0 + accumbytes;
assert(a1 >= a0);
overflow = (a1 >= prof_interval);
if (overflow) {
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
malloc_mutex_lock(tsdn, &prof_accum->mtx);
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;
#ifdef JEMALLOC_ATOMIC_U64
+ a0 = atomic_load_u64(&prof_accum->accumbytes, ATOMIC_RELAXED);
do {
- a0 = atomic_read_u64(&prof_accum->accumbytes);
a1 = (a0 >= LARGE_MINCLASS - usize) ? a0 - (LARGE_MINCLASS -
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
malloc_mutex_lock(tsdn, &prof_accum->mtx);
a0 = prof_accum->accumbytes;
diff --git a/include/jemalloc/internal/prof_structs.h b/include/jemalloc/internal/prof_structs.h
index afff6aa..fba8c29 100644
--- a/include/jemalloc/internal/prof_structs.h
+++ b/include/jemalloc/internal/prof_structs.h
@@ -18,8 +18,10 @@ typedef struct {
struct prof_accum_s {
#ifndef JEMALLOC_ATOMIC_U64
malloc_mutex_t mtx;
-#endif
uint64_t accumbytes;
+#else
+ atomic_u64_t accumbytes;
+#endif
};
struct prof_cnt_s {