summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2008-03-31 09:07:24 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2008-03-31 09:07:24 +0000
commit26aa8b09dbc2de1c7bdd97921a273511d585e043 (patch)
treeefb400bafcf30f832e1418d3a8e448b01d7d1293
parenteddf674157b304f167d965ccff80ec223b7f9ab1 (diff)
downloadrsyslog-26aa8b09dbc2de1c7bdd97921a273511d585e043.tar.gz
rsyslog-26aa8b09dbc2de1c7bdd97921a273511d585e043.tar.xz
rsyslog-26aa8b09dbc2de1c7bdd97921a273511d585e043.zip
worked a bit on atomic memory operations to support problem-free threading
(only at non-intrusive places)
-rw-r--r--ChangeLog4
-rw-r--r--atomic.h8
-rw-r--r--debug.c2
-rw-r--r--modules.c2
-rw-r--r--msg.c19
5 files changed, 29 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index bfe7f406..d51ff510 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,10 @@ Version 3.12.6 (rgerhards), 2008-04-??
supports multiple opens of the same module without any memory footprint.
- removed --enable-mudflap, added --enable-valgrind ./configure setting
- bugfix: tcp receiver could segfault due to uninitialized variable
+- docfix: queue doc had a wrong directive name that prevented max worker
+ threads to be correctly set
+- worked a bit on atomic memory operations to support problem-free
+ threading (only at non-intrusive places)
---------------------------------------------------------------------------
Version 3.12.5 (rgerhards), 2008-03-28
- changed default for "last message repeated n times", which is now
diff --git a/atomic.h b/atomic.h
index 28ed24e5..1883e030 100644
--- a/atomic.h
+++ b/atomic.h
@@ -6,6 +6,9 @@
* because in the non-presence of them, we simply do it without atomicitiy.
* Which, for word-aligned data types, usually (but only usually!) should work.
*
+ * We are using the functions described in
+ * http:/gcc.gnu.org/onlinedocs/gcc/Atomic-Builtins.html
+ *
* THESE MACROS MUST ONLY BE USED WITH WORD-SIZED DATA TYPES!
*
* Copyright 2008 Rainer Gerhards and Adiscon GmbH.
@@ -32,6 +35,9 @@
#ifndef INCLUDED_ATOMIC_H
#define INCLUDED_ATOMIC_H
-#define ATOMIC_INC(data) __sync_fetch_and_add(&data, 1);
+/* set the following to 1 if we have atomic operations (and #undef it otherwise) */
+#define DO_HAVE_ATOMICS 1
+#define ATOMIC_INC(data) ((void) __sync_fetch_and_add(&data, 1))
+#define ATOMIC_DEC_AND_FETCH(data) __sync_sub_and_fetch(&data, 1)
#endif /* #ifndef INCLUDED_ATOMIC_H */
diff --git a/debug.c b/debug.c
index 350bb6fb..29c65cf1 100644
--- a/debug.c
+++ b/debug.c
@@ -660,7 +660,9 @@ static void dbgCallStackDestruct(void *arg)
free(pThrd->pszThrdName);
}
+ pthread_mutex_lock(&mutCallStack);
DLL_Del(CallStack, pThrd);
+ pthread_mutex_unlock(&mutCallStack);
}
diff --git a/modules.c b/modules.c
index ad78e6e8..b6164f91 100644
--- a/modules.c
+++ b/modules.c
@@ -87,7 +87,7 @@ modUsrAdd(modInfo_t *pThis, char *pszUsr)
pThis->pModUsrRoot = pUsr;
finalize_it:
- ENDfunc
+ ENDfunc;
}
diff --git a/msg.c b/msg.c
index 0dd8f416..76ea2f72 100644
--- a/msg.c
+++ b/msg.c
@@ -43,6 +43,7 @@
#include "var.h"
#include "datetime.h"
#include "regexp.h"
+#include "atomic.h"
/* static data */
DEFobjStaticHelpers
@@ -241,9 +242,15 @@ finalize_it:
BEGINobjDestruct(msg) /* be sure to specify the object type also in END and CODESTART macros! */
+ int currRefCount;
CODESTARTobjDestruct(msg)
/* DEV Debugging only ! dbgprintf("msgDestruct\t0x%lx, Ref now: %d\n", (unsigned long)pM, pM->iRefCount - 1); */
- if(--pThis->iRefCount == 0)
+# ifdef DO_HAVE_ATOMICS
+ currRefCount = ATOMIC_DEC_AND_FETCH(pThis->iRefCount);
+# else
+ currRefCount = --pThis->iRefCount;
+# endif
+ if(currRefCount == 0)
{
/* DEV Debugging Only! dbgprintf("msgDestruct\t0x%lx, RefCount now 0, doing DESTROY\n", (unsigned long)pThis); */
if(pThis->pszUxTradMsg != NULL)
@@ -438,9 +445,13 @@ finalize_it:
msg_t *MsgAddRef(msg_t *pM)
{
assert(pM != NULL);
- MsgLock(pM);
- pM->iRefCount++;
- MsgUnlock(pM);
+# ifdef DO_HAVE_ATOMICS
+ ATOMIC_INC(pM->iRefCount);
+# else
+ MsgLock(pM);
+ pM->iRefCount++;
+ MsgUnlock(pM);
+# endif
/* DEV debugging only! dbgprintf("MsgAddRef\t0x%x done, Ref now: %d\n", (int)pM, pM->iRefCount);*/
return(pM);
}