diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2008-03-31 09:07:24 +0000 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2008-03-31 09:07:24 +0000 |
commit | 26aa8b09dbc2de1c7bdd97921a273511d585e043 (patch) | |
tree | efb400bafcf30f832e1418d3a8e448b01d7d1293 /msg.c | |
parent | eddf674157b304f167d965ccff80ec223b7f9ab1 (diff) | |
download | rsyslog-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.c | 19 |
1 files changed, 15 insertions, 4 deletions
@@ -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); } |