summaryrefslogtreecommitdiffstats
path: root/msg.c
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 /msg.c
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)
Diffstat (limited to 'msg.c')
-rw-r--r--msg.c19
1 files changed, 15 insertions, 4 deletions
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);
}