[PATCH 07/11] Disallow *_tsd_get() = value assignments
Mike Hommey
mh+jemalloc at glandium.org
Wed Apr 18 09:29:46 PDT 2012
From: Mike Hommey <mh at glandium.org>
---
include/jemalloc/internal/tsd.h | 8 +++---
src/ctl.c | 4 +--
src/jemalloc.c | 51 +++++++++++++++++++++++++++------------
3 files changed, 41 insertions(+), 22 deletions(-)
diff --git a/include/jemalloc/internal/tsd.h b/include/jemalloc/internal/tsd.h
index 35ae5e3..aee37b1 100644
--- a/include/jemalloc/internal/tsd.h
+++ b/include/jemalloc/internal/tsd.h
@@ -62,7 +62,7 @@ struct malloc_tsd_cleanup_s {
#define malloc_tsd_protos(a_attr, a_name, a_type) \
a_attr bool \
a_name##_tsd_boot(void); \
-a_attr a_type * \
+a_attr a_type const * \
a_name##_tsd_get(void); \
a_attr void \
a_name##_tsd_set(a_type *val);
@@ -132,7 +132,7 @@ a_name##_tsd_boot(void) \
return (false); \
} \
/* Get/set. */ \
-a_attr a_type * \
+a_attr a_type const * \
a_name##_tsd_get(void) \
{ \
\
@@ -164,7 +164,7 @@ a_name##_tsd_boot(void) \
return (false); \
} \
/* Get/set. */ \
-a_attr a_type * \
+a_attr a_type const * \
a_name##_tsd_get(void) \
{ \
\
@@ -265,7 +265,7 @@ a_name##_tsd_get_wrapper(void) \
} \
return (wrapper); \
} \
-a_attr a_type * \
+a_attr a_type const * \
a_name##_tsd_get(void) \
{ \
a_name##_tsd_wrapper_t *wrapper; \
diff --git a/src/ctl.c b/src/ctl.c
index 98ea3d1..0c1c8f8 100644
--- a/src/ctl.c
+++ b/src/ctl.c
@@ -1079,11 +1079,11 @@ label_return:
CTL_RO_NL_CGEN(config_stats, thread_allocated,
thread_allocated_tsd_get()->allocated, uint64_t)
CTL_RO_NL_CGEN(config_stats, thread_allocatedp,
- &thread_allocated_tsd_get()->allocated, uint64_t *)
+ &thread_allocated_tsd_get()->allocated, uint64_t const *)
CTL_RO_NL_CGEN(config_stats, thread_deallocated,
thread_allocated_tsd_get()->deallocated, uint64_t)
CTL_RO_NL_CGEN(config_stats, thread_deallocatedp,
- &thread_allocated_tsd_get()->deallocated, uint64_t *)
+ &thread_allocated_tsd_get()->deallocated, uint64_t const *)
/******************************************************************************/
diff --git a/src/jemalloc.c b/src/jemalloc.c
index d4b681b..db0b2b5 100644
--- a/src/jemalloc.c
+++ b/src/jemalloc.c
@@ -818,8 +818,11 @@ label_oom:
if (config_prof && opt_prof && ret != NULL)
prof_malloc(ret, usize, cnt);
if (config_stats && ret != NULL) {
+ thread_allocated_t ta;
assert(usize == isalloc(ret, config_prof));
- thread_allocated_tsd_get()->allocated += usize;
+ ta = *thread_allocated_tsd_get();
+ ta.allocated += usize;
+ thread_allocated_tsd_set(&ta);
}
UTRACE(0, size, ret);
JEMALLOC_VALGRIND_MALLOC(ret != NULL, ret, usize, false);
@@ -911,8 +914,11 @@ imemalign(void **memptr, size_t alignment, size_t size,
label_return:
if (config_stats && result != NULL) {
+ thread_allocated_t ta;
assert(usize == isalloc(result, config_prof));
- thread_allocated_tsd_get()->allocated += usize;
+ ta = *thread_allocated_tsd_get();
+ ta.allocated += usize;
+ thread_allocated_tsd_set(&ta);
}
if (config_prof && opt_prof && result != NULL)
prof_malloc(result, usize, cnt);
@@ -1017,8 +1023,11 @@ label_return:
if (config_prof && opt_prof && ret != NULL)
prof_malloc(ret, usize, cnt);
if (config_stats && ret != NULL) {
+ thread_allocated_t ta;
assert(usize == isalloc(ret, config_prof));
- thread_allocated_tsd_get()->allocated += usize;
+ ta = *thread_allocated_tsd_get();
+ ta.allocated += usize;
+ thread_allocated_tsd_set(&ta);
}
UTRACE(0, num_size, ret);
JEMALLOC_VALGRIND_MALLOC(ret != NULL, ret, usize, true);
@@ -1162,11 +1171,12 @@ label_return:
if (config_prof && opt_prof)
prof_realloc(ret, usize, cnt, old_size, old_ctx);
if (config_stats && ret != NULL) {
- thread_allocated_t *ta;
+ thread_allocated_t ta;
assert(usize == isalloc(ret, config_prof));
- ta = thread_allocated_tsd_get();
- ta->allocated += usize;
- ta->deallocated += old_size;
+ ta = *thread_allocated_tsd_get();
+ ta.allocated += usize;
+ ta.deallocated += old_size;
+ thread_allocated_tsd_set(&ta);
}
UTRACE(ptr, size, ret);
JEMALLOC_VALGRIND_REALLOC(ret, usize, ptr, old_size, old_rzsize, false);
@@ -1190,8 +1200,11 @@ je_free(void *ptr)
prof_free(ptr, usize);
} else if (config_stats || config_valgrind)
usize = isalloc(ptr, config_prof);
- if (config_stats)
- thread_allocated_tsd_get()->deallocated += usize;
+ if (config_stats) {
+ thread_allocated_t ta = *thread_allocated_tsd_get();
+ ta.deallocated += usize;
+ thread_allocated_tsd_set(&ta);
+ }
if (config_valgrind && opt_valgrind)
rzsize = p2rz(ptr);
iqalloc(ptr);
@@ -1408,8 +1421,11 @@ je_allocm(void **ptr, size_t *rsize, size_t size, int flags)
*ptr = p;
if (config_stats) {
+ thread_allocated_t ta;
assert(usize == isalloc(p, config_prof));
- thread_allocated_tsd_get()->allocated += usize;
+ ta = *thread_allocated_tsd_get();
+ ta.allocated += usize;
+ thread_allocated_tsd_set(&ta);
}
UTRACE(0, size, p);
JEMALLOC_VALGRIND_MALLOC(true, p, usize, zero);
@@ -1512,10 +1528,10 @@ je_rallocm(void **ptr, size_t *rsize, size_t size, size_t extra, int flags)
*ptr = q;
if (config_stats) {
- thread_allocated_t *ta;
- ta = thread_allocated_tsd_get();
- ta->allocated += usize;
- ta->deallocated += old_size;
+ thread_allocated_t ta = *thread_allocated_tsd_get();
+ ta.allocated += usize;
+ ta.deallocated += old_size;
+ thread_allocated_tsd_set(&ta);
}
UTRACE(p, size, q);
JEMALLOC_VALGRIND_REALLOC(q, usize, p, old_size, old_rzsize, zero);
@@ -1575,8 +1591,11 @@ je_dallocm(void *ptr, int flags)
usize = isalloc(ptr, config_prof);
prof_free(ptr, usize);
}
- if (config_stats)
- thread_allocated_tsd_get()->deallocated += usize;
+ if (config_stats) {
+ thread_allocated_t ta = *thread_allocated_tsd_get();
+ ta.deallocated += usize;
+ thread_allocated_tsd_set(&ta);
+ }
if (config_valgrind && opt_valgrind)
rzsize = p2rz(ptr);
iqalloc(ptr);
--
1.7.10
More information about the jemalloc-discuss
mailing list