summaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2009-06-25 17:09:51 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2009-06-25 17:09:51 +0200
commit12dc91a157cf2375596920c1f4f7c361ad717103 (patch)
treefe2976eae8583b979d618386d78776e3b37eb341 /runtime
parent1f79c785975261e4158c9b85f6451d5bd00b2495 (diff)
downloadrsyslog-12dc91a157cf2375596920c1f4f7c361ad717103.tar.gz
rsyslog-12dc91a157cf2375596920c1f4f7c361ad717103.tar.xz
rsyslog-12dc91a157cf2375596920c1f4f7c361ad717103.zip
backported "clean" increment of memory trim counter (not protected by mutex)
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);
}
}