summaryrefslogtreecommitdiffstats
path: root/include/jemalloc
diff options
context:
space:
mode:
authorDavid Goldblatt <davidgoldblatt@fb.com>2017-04-05 01:34:01 (GMT)
committerDavid Goldblatt <davidtgoldblatt@gmail.com>2017-04-05 23:25:37 (GMT)
commit5dcc13b342b3ffb38a1215ab2584b8cb12c46030 (patch)
treea5e745a7ca93bf0c24674fb054f9bae0881746a0 /include/jemalloc
parent492a941f493f77f60062039b60040f426aa7ee45 (diff)
downloadjemalloc-5dcc13b342b3ffb38a1215ab2584b8cb12c46030.zip
jemalloc-5dcc13b342b3ffb38a1215ab2584b8cb12c46030.tar.gz
jemalloc-5dcc13b342b3ffb38a1215ab2584b8cb12c46030.tar.bz2
Make the mutex n_waiting_thds field a C11-style atomic
Diffstat (limited to 'include/jemalloc')
-rw-r--r--include/jemalloc/internal/mutex_inlines.h14
-rw-r--r--include/jemalloc/internal/mutex_structs.h2
-rw-r--r--include/jemalloc/internal/mutex_types.h3
3 files changed, 15 insertions, 4 deletions
diff --git a/include/jemalloc/internal/mutex_inlines.h b/include/jemalloc/internal/mutex_inlines.h
index 3a12a72..0552e19 100644
--- a/include/jemalloc/internal/mutex_inlines.h
+++ b/include/jemalloc/internal/mutex_inlines.h
@@ -40,7 +40,12 @@ malloc_mutex_prof_merge(mutex_prof_data_t *sum, mutex_prof_data_t *data) {
if (sum->max_n_thds < data->max_n_thds) {
sum->max_n_thds = data->max_n_thds;
}
- sum->n_waiting_thds += data->n_waiting_thds;
+ uint32_t cur_n_waiting_thds = atomic_load_u32(&sum->n_waiting_thds,
+ ATOMIC_RELAXED);
+ uint32_t new_n_waiting_thds = cur_n_waiting_thds + atomic_load_u32(
+ &data->n_waiting_thds, ATOMIC_RELAXED);
+ atomic_store_u32(&sum->n_waiting_thds, new_n_waiting_thds,
+ ATOMIC_RELAXED);
sum->n_owner_switches += data->n_owner_switches;
sum->n_lock_ops += data->n_lock_ops;
}
@@ -91,9 +96,14 @@ malloc_mutex_prof_read(tsdn_t *tsdn, mutex_prof_data_t *data,
/* Can only read holding the mutex. */
malloc_mutex_assert_owner(tsdn, mutex);
+ /*
+ * Not *really* allowed (we shouldn't be doing non-atomic loads of
+ * atomic data), but the mutex protection makes this safe, and writing
+ * a member-for-member copy is tedious for this situation.
+ */
*data = *source;
/* n_wait_thds is not reported (modified w/o locking). */
- data->n_waiting_thds = 0;
+ atomic_store_u32(&data->n_waiting_thds, 0, ATOMIC_RELAXED);
}
#endif
diff --git a/include/jemalloc/internal/mutex_structs.h b/include/jemalloc/internal/mutex_structs.h
index 5dddb84..ff090b2 100644
--- a/include/jemalloc/internal/mutex_structs.h
+++ b/include/jemalloc/internal/mutex_structs.h
@@ -17,7 +17,7 @@ struct mutex_prof_data_s {
/* Max # of threads waiting for the mutex at the same time. */
uint32_t max_n_thds;
/* Current # of threads waiting on the lock. Atomic synced. */
- uint32_t n_waiting_thds;
+ atomic_u32_t n_waiting_thds;
/*
* Data touched on the fast path. These are modified right after we
diff --git a/include/jemalloc/internal/mutex_types.h b/include/jemalloc/internal/mutex_types.h
index bd26149..e658937 100644
--- a/include/jemalloc/internal/mutex_types.h
+++ b/include/jemalloc/internal/mutex_types.h
@@ -35,7 +35,8 @@ typedef struct malloc_mutex_s malloc_mutex_t;
#endif
#define LOCK_PROF_DATA_INITIALIZER \
- {NSTIME_ZERO_INITIALIZER, NSTIME_ZERO_INITIALIZER, 0, 0, 0, 0, 0, NULL, 0}
+ {NSTIME_ZERO_INITIALIZER, NSTIME_ZERO_INITIALIZER, 0, 0, 0, \
+ ATOMIC_INIT(0), 0, NULL, 0}
#ifdef _WIN32
# define MALLOC_MUTEX_INITIALIZER