summaryrefslogtreecommitdiffstats
path: root/runtime/msg.c
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/msg.c
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/msg.c')
-rw-r--r--runtime/msg.c8
1 files changed, 5 insertions, 3 deletions
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);
}
}