SCTime_t pktts; /**< current packet time of this thread
* (offline mode) */
- uint32_t sys_sec_stamp; /**< timestamp in seconds of the real system
+ SCTime_t sys_sec_stamp; /**< timestamp in real system
* time when the pktts was last updated. */
} Thread;
int idx = id - 1;
Thread *t = &thread_store.threads[idx];
t->pktts = ts;
- struct timeval systs;
- gettimeofday(&systs, NULL);
- t->sys_sec_stamp = (uint32_t)systs.tv_sec;
+ SCTime_t now = SCTimeGetTime();
+
+#ifdef DEBUG
+ if (t->sys_sec_stamp.secs != 0) {
+ SCTime_t tmpts = SCTIME_ADD_SECS(t->sys_sec_stamp, 3);
+ if (SCTIME_CMP_LT(tmpts, now)) {
+ SCLogDebug("%s: thread slept for %u secs", t->name, (uint32_t)(now.secs - tmpts.secs));
+ }
+ }
+#endif
+
+ t->sys_sec_stamp = now;
SCMutexUnlock(&thread_store_lock);
}
bool TmThreadsTimeSubsysIsReady(void)
{
+ static SCTime_t nullts = SCTIME_INITIALIZER;
bool ready = true;
SCMutexLock(&thread_store_lock);
for (size_t s = 0; s < thread_store.threads_size; s++) {
break;
if (t->type != TVT_PPT)
continue;
- if (t->sys_sec_stamp == 0) {
+ if (SCTIME_CMP_EQ(t->sys_sec_stamp, nullts)) {
ready = false;
break;
}
void TmThreadsInitThreadsTimestamp(const SCTime_t ts)
{
- struct timeval systs;
- gettimeofday(&systs, NULL);
+ SCTime_t now = SCTimeGetTime();
SCMutexLock(&thread_store_lock);
for (size_t s = 0; s < thread_store.threads_size; s++) {
Thread *t = &thread_store.threads[s];
if (t->type != TVT_PPT)
continue;
t->pktts = ts;
- t->sys_sec_stamp = (uint32_t)systs.tv_sec;
+ t->sys_sec_stamp = now;
}
SCMutexUnlock(&thread_store_lock);
}
void TmThreadsGetMinimalTimestamp(struct timeval *ts)
{
struct timeval local = { 0 };
- static struct timeval nullts;
+ static SCTime_t nullts = SCTIME_INITIALIZER;
bool set = false;
size_t s;
- struct timeval systs;
- gettimeofday(&systs, NULL);
+ SCTime_t now = SCTimeGetTime();
SCMutexLock(&thread_store_lock);
for (s = 0; s < thread_store.threads_size; s++) {
/* only packet threads set timestamps based on packets */
if (t->type != TVT_PPT)
continue;
- struct timeval pkttv = { .tv_sec = SCTIME_SECS(t->pktts),
- .tv_usec = SCTIME_USECS(t->pktts) };
- if (!(timercmp(&pkttv, &nullts, ==))) {
+ if (SCTIME_CMP_NEQ(t->pktts, nullts)) {
+ SCTime_t sys_sec_stamp = SCTIME_ADD_SECS(t->sys_sec_stamp, 1);
/* ignore sleeping threads */
- if (t->sys_sec_stamp + 1 < (uint32_t)systs.tv_sec)
+ if (SCTIME_CMP_LT(sys_sec_stamp, now))
continue;
if (!set) {