Switch time api from mutex to spinlock.

remotes/origin/master-1.0.x
Victor Julien 15 years ago
parent 19584d0416
commit e1a8c8f76c

@ -673,6 +673,7 @@ int main(int argc, char **argv)
/* Initializations for global vars, queues, etc (memsets, mutex init..) */ /* Initializations for global vars, queues, etc (memsets, mutex init..) */
GlobalInits(); GlobalInits();
TimeInit();
/* Load yaml configuration file if provided. */ /* Load yaml configuration file if provided. */
if (conf_filename != NULL) { if (conf_filename != NULL) {
@ -1132,6 +1133,7 @@ int main(int argc, char **argv)
RunModeShutDown(); RunModeShutDown();
OutputDeregisterAll(); OutputDeregisterAll();
TimeDeinit();
#ifdef __SC_CUDA_SUPPORT__ #ifdef __SC_CUDA_SUPPORT__
/* all cuda contexts attached to any threads should be free by now. /* all cuda contexts attached to any threads should be free by now.

@ -29,9 +29,18 @@
#include "util-debug.h" #include "util-debug.h"
static struct timeval current_time = { 0, 0 }; static struct timeval current_time = { 0, 0 };
static SCMutex current_time_mutex = PTHREAD_MUTEX_INITIALIZER; //static SCMutex current_time_mutex = PTHREAD_MUTEX_INITIALIZER;
static SCSpinlock current_time_spinlock;
static char live = TRUE; static char live = TRUE;
void TimeInit(void) {
SCSpinInit(&current_time_spinlock, 0);
}
void TimeDeinit(void) {
SCSpinDestroy(&current_time_spinlock);
}
void TimeModeSetLive(void) void TimeModeSetLive(void)
{ {
live = TRUE; live = TRUE;
@ -52,14 +61,14 @@ void TimeSet(struct timeval *tv)
if (tv == NULL) if (tv == NULL)
return; return;
SCMutexLock(&current_time_mutex); SCSpinLock(&current_time_spinlock);
current_time.tv_sec = tv->tv_sec; current_time.tv_sec = tv->tv_sec;
current_time.tv_usec = tv->tv_usec; current_time.tv_usec = tv->tv_usec;
SCLogDebug("time set to %" PRIuMAX " sec, %" PRIuMAX " usec", SCLogDebug("time set to %" PRIuMAX " sec, %" PRIuMAX " usec",
(uintmax_t)current_time.tv_sec, (uintmax_t)current_time.tv_usec); (uintmax_t)current_time.tv_sec, (uintmax_t)current_time.tv_usec);
SCMutexUnlock(&current_time_mutex); SCSpinUnlock(&current_time_spinlock);
} }
/** \brief set the time to "gettimeofday" meant for testing */ /** \brief set the time to "gettimeofday" meant for testing */
@ -80,10 +89,10 @@ void TimeGet(struct timeval *tv)
if (live == TRUE) { if (live == TRUE) {
gettimeofday(tv, NULL); gettimeofday(tv, NULL);
} else { } else {
SCMutexLock(&current_time_mutex); SCSpinLock(&current_time_spinlock);
tv->tv_sec = current_time.tv_sec; tv->tv_sec = current_time.tv_sec;
tv->tv_usec = current_time.tv_usec; tv->tv_usec = current_time.tv_usec;
SCMutexUnlock(&current_time_mutex); SCSpinUnlock(&current_time_spinlock);
} }
SCLogDebug("time we got is %" PRIuMAX " sec, %" PRIuMAX " usec", SCLogDebug("time we got is %" PRIuMAX " sec, %" PRIuMAX " usec",

@ -34,6 +34,9 @@ typedef struct SCTimeval32_ {
uint32_t tv_usec; uint32_t tv_usec;
} SCTimeval32; } SCTimeval32;
void TimeInit(void);
void TimeDeinit(void);
void TimeSet(struct timeval *); void TimeSet(struct timeval *);
void TimeGet(struct timeval *); void TimeGet(struct timeval *);

Loading…
Cancel
Save