diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2010-03-05 09:36:45 +0100 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2010-03-05 09:36:45 +0100 |
commit | 129eeca64bf2bd00ad85a3f1c4fbfa419231fa8d (patch) | |
tree | 0698e5e145fd637a28e1c9a944e87e6aed12b8db /tools/omfile.c | |
parent | b54d56b9f8c87cdff336af25b3089a3ed732b8c8 (diff) | |
download | rsyslog-129eeca64bf2bd00ad85a3f1c4fbfa419231fa8d.tar.gz rsyslog-129eeca64bf2bd00ad85a3f1c4fbfa419231fa8d.tar.xz rsyslog-129eeca64bf2bd00ad85a3f1c4fbfa419231fa8d.zip |
relaxed need for atomic builtins
Diffstat (limited to 'tools/omfile.c')
-rw-r--r-- | tools/omfile.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tools/omfile.c b/tools/omfile.c index 424dd70f..1f203852 100644 --- a/tools/omfile.c +++ b/tools/omfile.c @@ -89,12 +89,31 @@ static uint64 clockFileAccess = 0; static unsigned clockFileAccess = 0; #endif /* and the "tick" function */ +#ifdef HAVE_ATOMIC_BUILTINS static inline uint64 getClockFileAccess(void) { return ATOMIC_INC_AND_FETCH(clockFileAccess); } +#else +/* if we do not have atomics, we need to guard this via a mutex. + * the reason is that otherwise cache lookups may fail. That function + * requires the highest current value, and we can not provide that + * without using atomic instructions and mutexes. + * rgerhards, 2010-03-05 + */ +static pthread_mutex_t mutClock; +static uint64 +getClockFileAccess(void) +{ + uint64 retVal; + d_pthread_mutex_lock(&mutClock); + retVal = ++clockFileAccess; + d_pthread_mutex_unlock(&mutClock); + return retVal; +} +#endif /* #ifdef HAVE_ATOMIC_BUILTINS */ /* The following structure is a dynafile name cache entry. */ @@ -827,6 +846,9 @@ CODESTARTmodExit objRelease(errmsg, CORE_COMPONENT); objRelease(strm, CORE_COMPONENT); free(pszFileDfltTplName); +# ifndef HAVE_ATOMIC_BUILTINS + pthread_mutex_destroy(&mutClock); +# endif ENDmodExit @@ -844,6 +866,11 @@ CODESTARTmodInit CODEmodInit_QueryRegCFSLineHdlr CHKiRet(objUse(errmsg, CORE_COMPONENT)); CHKiRet(objUse(strm, CORE_COMPONENT)); + +# ifndef HAVE_ATOMIC_BUILTINS + pthread_mutex_init(&mutClock, NULL); +# endif + INITChkCoreFeature(bCoreSupportsBatching, CORE_FEATURE_BATCHING); DBGPRINTF("omfile: %susing transactional output interface.\n", bCoreSupportsBatching ? "" : "not "); CHKiRet(omsdRegCFSLineHdlr((uchar *)"dynafilecachesize", 0, eCmdHdlrInt, (void*) setDynaFileCacheSize, NULL, STD_LOADABLE_MODULE_ID)); |