diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2008-03-31 07:26:43 +0000 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2008-03-31 07:26:43 +0000 |
commit | af1b9c5140e0258d4576568968337cc77b016cd7 (patch) | |
tree | b9c44819b409af5fe3f5e08b599d0eff9eb14037 | |
parent | c3460c09e709c4582c871e9c61d6a16abca33411 (diff) | |
download | rsyslog-af1b9c5140e0258d4576568968337cc77b016cd7.tar.gz rsyslog-af1b9c5140e0258d4576568968337cc77b016cd7.tar.xz rsyslog-af1b9c5140e0258d4576568968337cc77b016cd7.zip |
added initial support for atomic operations
-rw-r--r-- | Makefile.am | 3 | ||||
-rw-r--r-- | atomic.h | 37 | ||||
-rw-r--r-- | debug.c | 5 |
3 files changed, 41 insertions, 4 deletions
diff --git a/Makefile.am b/Makefile.am index 104b962a..31737516 100644 --- a/Makefile.am +++ b/Makefile.am @@ -87,7 +87,8 @@ rsyslogd_SOURCES = \ iminternal.c \ iminternal.h \ action.c \ - action.h + action.h \ + atomic.h rsyslogd_CPPFLAGS = -D_PATH_MODDIR=\"$(pkglibdir)/\" $(pthreads_cflags) rsyslogd_LDADD = $(zlib_libs) $(pthreads_libs) $(dl_libs) $(rt_libs) diff --git a/atomic.h b/atomic.h new file mode 100644 index 00000000..28ed24e5 --- /dev/null +++ b/atomic.h @@ -0,0 +1,37 @@ +/* This header supplies atomic operations. So far, we rely on GCC's + * atomic builtins. I have no idea if we can check them via autotools, + * but I am making the necessary provisioning to live without them if + * they are not available. Please note that you should only use the macros + * here if you think you can actually live WITHOUT an explicit atomic operation, + * 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. + * + * THESE MACROS MUST ONLY BE USED WITH WORD-SIZED DATA TYPES! + * + * Copyright 2008 Rainer Gerhards and Adiscon GmbH. + * + * This file is part of rsyslog. + * + * Rsyslog is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Rsyslog is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Rsyslog. If not, see <http://www.gnu.org/licenses/>. + * + * A copy of the GPL can be found in the file "COPYING" in this distribution. + */ +#include "config.h" /* autotools! */ + +#ifndef INCLUDED_ATOMIC_H +#define INCLUDED_ATOMIC_H + +#define ATOMIC_INC(data) __sync_fetch_and_add(&data, 1); + +#endif /* #ifndef INCLUDED_ATOMIC_H */ @@ -32,8 +32,6 @@ * * A copy of the GPL can be found in the file "COPYING" in this distribution. */ - - #include "config.h" /* autotools! */ #include <stdio.h> #include <stdlib.h> @@ -47,6 +45,7 @@ #include "rsyslog.h" #include "debug.h" +#include "atomic.h" #include "obj.h" @@ -992,7 +991,7 @@ int dbgEntrFunc(dbgFuncDB_t **ppFuncDB, const char *file, const char *func, int } /* when we reach this point, we have a fully-initialized FuncDB! */ - pFuncDB->nTimesCalled++; + ATOMIC_INC(pFuncDB->nTimesCalled); if(bLogFuncFlow && dbgPrintNameIsInList((const uchar*)pFuncDB->file, printNameFileRoot)) dbgprintf("%s:%d: %s: enter\n", pFuncDB->file, pFuncDB->line, pFuncDB->func); if(pThrd->stackPtr >= (int) (sizeof(pThrd->callStack) / sizeof(dbgFuncDB_t*))) { |