diff options
Diffstat (limited to 'tools/omfile.c')
-rw-r--r-- | tools/omfile.c | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/tools/omfile.c b/tools/omfile.c index 5b672181..9562e9cf 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. */ @@ -123,7 +142,7 @@ static uid_t dirGID; /* GID to be used for newly created directories */ static int bCreateDirs = 1;/* auto-create directories for dynaFiles: 0 - no, 1 - yes */ static int bEnableSync = 0;/* enable syncing of files (no dash in front of pathname in conf): 0 - no, 1 - yes */ static int iZipLevel = 0; /* zip compression mode (0..9 as usual) */ -static bool bFlushOnTXEnd = 1;/* flush write buffers when transaction has ended? */ +static sbool bFlushOnTXEnd = 1;/* flush write buffers when transaction has ended? */ static int64 iIOBufSize = IOBUF_DFLT_SIZE; /* size of an io buffer */ static int iFlushInterval = FLUSH_INTRVL_DFLT; /* how often flush the output buffer on inactivity? */ uchar *pszFileDfltTplName = NULL; /* name of the default template to use */ @@ -139,7 +158,7 @@ typedef struct _instanceData { int fDirCreateMode; /* creation mode for mkdir() */ int bCreateDirs; /* auto-create directories? */ int bSyncFile; /* should the file by sync()'ed? 1- yes, 0- no */ - bool bForceChown; /* force chown() on existing files? */ + sbool bForceChown; /* force chown() on existing files? */ uid_t fileUID; /* IDs for creation */ uid_t dirUID; gid_t fileGID; @@ -158,7 +177,7 @@ typedef struct _instanceData { int iZipLevel; /* zip mode to use for this selector */ int iIOBufSize; /* size of associated io buffer */ int iFlushInterval; /* how fast flush buffer on inactivity? */ - bool bFlushOnTXEnd; /* flush write buffers when transaction has ended? */ + sbool bFlushOnTXEnd; /* flush write buffers when transaction has ended? */ } instanceData; @@ -839,6 +858,9 @@ CODESTARTmodExit objRelease(errmsg, CORE_COMPONENT); objRelease(strm, CORE_COMPONENT); free(pszFileDfltTplName); +# ifndef HAVE_ATOMIC_BUILTINS + pthread_mutex_destroy(&mutClock); +# endif ENDmodExit @@ -856,6 +878,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)); |