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 | |
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)
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | atomic.h | 8 | ||||
-rw-r--r-- | debug.c | 2 | ||||
-rw-r--r-- | modules.c | 2 | ||||
-rw-r--r-- | msg.c | 19 |
5 files changed, 29 insertions, 6 deletions
@@ -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 @@ -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 */ @@ -660,7 +660,9 @@ static void dbgCallStackDestruct(void *arg) free(pThrd->pszThrdName); } + pthread_mutex_lock(&mutCallStack); DLL_Del(CallStack, pThrd); + pthread_mutex_unlock(&mutCallStack); } @@ -87,7 +87,7 @@ modUsrAdd(modInfo_t *pThis, char *pszUsr) pThis->pModUsrRoot = pUsr; finalize_it: - ENDfunc + ENDfunc; } @@ -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); } |