summaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'runtime')
-rw-r--r--runtime/atomic.h1
-rw-r--r--runtime/msg.c8
2 files changed, 6 insertions, 3 deletions
diff --git a/runtime/atomic.h b/runtime/atomic.h
index f5ae9357..d5aaf56b 100644
--- a/runtime/atomic.h
+++ b/runtime/atomic.h
@@ -42,6 +42,7 @@
*/
#ifdef HAVE_ATOMIC_BUILTINS
# define ATOMIC_INC(data) ((void) __sync_fetch_and_add(&(data), 1))
+# define ATOMIC_INC_AND_FETCH(data) __sync_fetch_and_add(&(data), 1)
# define ATOMIC_DEC(data) ((void) __sync_sub_and_fetch(&(data), 1))
# define ATOMIC_DEC_AND_FETCH(data) __sync_sub_and_fetch(&(data), 1)
# define ATOMIC_FETCH_32BIT(data) ((unsigned) __sync_fetch_and_and(&(data), 0xffffffff))
diff --git a/runtime/msg.c b/runtime/msg.c
index cbdfff78..75933d68 100644
--- a/runtime/msg.c
+++ b/runtime/msg.c
@@ -607,10 +607,12 @@ CODESTARTobjDestruct(msg)
* operations on the counter. --- rgerhards, 2009-06-22.
*/
# if HAVE_MALLOC_TRIM
- { /* standard C requires a new block for a new variable definition! */
+ { /* standard C requires a new block for a new variable definition!
+ * To simplify matters, we use modulo arithmetic and live with the fact
+ * that we trim too often when the counter wraps.
+ */
static unsigned iTrimCtr = 1;
- if(iTrimCtr ++ % 100000 == 0) {
- iTrimCtr = 1;
+ if(ATOMIC_INC_AND_FETCH(iTrimCtr) % 100000 == 0) {
malloc_trim(128*1024);
}
}