summaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2010-06-08 08:25:56 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2010-06-08 08:25:56 +0200
commit220c57e7ebc49a56cc91fa31308b1563f83a95fb (patch)
treeb4295619e3121daa9766c38b542b15d6c5669760 /runtime
parentd9e64c16e52357bae1eb00fc8403c4e63d6365ca (diff)
downloadrsyslog-220c57e7ebc49a56cc91fa31308b1563f83a95fb.tar.gz
rsyslog-220c57e7ebc49a56cc91fa31308b1563f83a95fb.tar.xz
rsyslog-220c57e7ebc49a56cc91fa31308b1563f83a95fb.zip
bugfix: regression caused more locking action in msg.c than necessary
also: bugfix: mutexes used to similate atomic instructions were not destructed
Diffstat (limited to 'runtime')
-rw-r--r--runtime/atomic.h13
-rw-r--r--runtime/msg.c24
2 files changed, 25 insertions, 12 deletions
diff --git a/runtime/atomic.h b/runtime/atomic.h
index d8cdff7b..e5fafe04 100644
--- a/runtime/atomic.h
+++ b/runtime/atomic.h
@@ -42,7 +42,7 @@
# define ATOMIC_SUB(data, val, phlpmut) __sync_fetch_and_sub(data, val)
# define ATOMIC_ADD(data, val) __sync_fetch_and_add(&(data), val)
# define ATOMIC_INC(data, phlpmut) ((void) __sync_fetch_and_add(data, 1))
-# define ATOMIC_INC_AND_FETCH(data) __sync_fetch_and_add(&(data), 1)
+# define ATOMIC_INC_AND_FETCH(data, phlpmut) __sync_fetch_and_add(data, 1)
# define ATOMIC_DEC(data, phlpmut) ((void) __sync_sub_and_fetch(data, 1))
# define ATOMIC_DEC_AND_FETCH(data, phlpmut) __sync_sub_and_fetch(data, 1)
# define ATOMIC_FETCH_32BIT(data, phlpmut) ((unsigned) __sync_fetch_and_and(data, 0xffffffff))
@@ -109,6 +109,15 @@
}
static inline int
+ ATOMIC_INC_AND_FETCH(int *data, pthread_mutex_t *phlpmut) {
+ int val;
+ pthread_mutex_lock(phlpmut);
+ val = ++(*data);
+ pthread_mutex_unlock(phlpmut);
+ return(val);
+ }
+
+ static inline int
ATOMIC_DEC_AND_FETCH(int *data, pthread_mutex_t *phlpmut) {
int val;
pthread_mutex_lock(phlpmut);
@@ -139,7 +148,7 @@
#endif
# define DEF_ATOMIC_HELPER_MUT(x) pthread_mutex_t x
# define INIT_ATOMIC_HELPER_MUT(x) pthread_mutex_init(&(x), NULL)
-# define DESTROY_ATOMIC_HELPER_MUT(x) pthread_mutex_init(&(x), NULL)
+# define DESTROY_ATOMIC_HELPER_MUT(x) pthread_mutex_destroy(&(x))
# define PREFER_ATOMIC_INC(data) ((void) ++data)
diff --git a/runtime/msg.c b/runtime/msg.c
index dc354947..1b188263 100644
--- a/runtime/msg.c
+++ b/runtime/msg.c
@@ -278,6 +278,11 @@ static char *syslog_severity_names[8] = { "emerg", "alert", "crit", "err", "warn
static char *syslog_number_names[24] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14",
"15", "16", "17", "18", "19", "20", "21", "22", "23" };
+/* global variables */
+#if defined(HAVE_MALLOC_TRIM) && !defined(HAVE_ATOMIC_BUILTINS)
+static pthread_mutex_t mutTrimCtr; /* mutex to handle malloc trim */
+#endif
+
/* some forward declarations */
static int getAPPNAMELen(msg_t *pM, sbool bLockMutex);
@@ -784,6 +789,9 @@ static inline void freeHOSTNAME(msg_t *pThis)
BEGINobjDestruct(msg) /* be sure to specify the object type also in END and CODESTART macros! */
int currRefCount;
+# if HAVE_MALLOC_TRIM
+ int currCnt;
+# endif
CODESTARTobjDestruct(msg)
/* DEV Debugging only ! dbgprintf("msgDestruct\t0x%lx, Ref now: %d\n", (unsigned long)pThis, pThis->iRefCount - 1); */
# ifdef HAVE_ATOMIC_BUILTINS
@@ -843,18 +851,10 @@ CODESTARTobjDestruct(msg)
* that we trim too often when the counter wraps.
*/
static unsigned iTrimCtr = 1;
-# ifdef HAVE_ATOMICS
- if(ATOMIC_INC_AND_FETCH(iTrimCtr) % 100000 == 0) {
- malloc_trim(128*1024);
- }
-# else
-static pthread_mutex_t mutTrimCtr = PTHREAD_MUTEX_INITIALIZER;
- d_pthread_mutex_lock(&mutTrimCtr);
- if(iTrimCtr++ % 100000 == 0) {
+ currCnt = ATOMIC_INC_AND_FETCH(&iTrimCtr, &mutTrimCtr);
+ if(currCnt % 100000 == 0) {
malloc_trim(128*1024);
}
- d_pthread_mutex_unlock(&mutTrimCtr);
-# endif
}
# endif
} else {
@@ -3185,6 +3185,10 @@ BEGINObjClassInit(msg, 1, OBJ_IS_CORE_MODULE)
funcUnlock = MsgLockingDummy;
funcDeleteMutex = MsgLockingDummy;
funcMsgPrepareEnqueue = MsgLockingDummy;
+ /* some more inits */
+# if HAVE_MALLOC_TRIM
+ INIT_ATOMIC_HELPER_MUT(mutTrimCtr);
+# endif
ENDObjClassInit(msg)
/* vim:set ai:
*/