static uint16_t counters_global_id = 0;
-void StatsPublicThreadContextInit(StatsPublicThreadContext *t)
+static void StatsPublicThreadContextInit(StatsPublicThreadContext *t)
{
SCMutexInit(&t->m, NULL);
}
-void StatsPublicThreadContextCleanup(StatsPublicThreadContext *t)
+static void StatsPublicThreadContextCleanup(StatsPublicThreadContext *t)
{
SCMutexLock(&t->m);
StatsReleaseCounters(t->head);
+ t->head = NULL;
+ t->perf_flag = 0;
+ t->curr_id = 0;
SCMutexUnlock(&t->m);
-
SCMutexDestroy(&t->m);
}
memset(temp, 0, sizeof(StatsThreadStore));
temp->ctx = pctx;
-
- temp->name = SCStrdup(thread_name);
- if (unlikely(temp->name == NULL)) {
- SCFree(temp);
- SCMutexUnlock(&stats_ctx->sts_lock);
- return 0;
- }
+ temp->name = thread_name;
temp->next = stats_ctx->sts;
stats_ctx->sts = temp;
if (pca->head != NULL) {
SCFree(pca->head);
pca->head = NULL;
+ pca->size = 0;
}
pca->initialized = 0;
}
return;
}
+void StatsThreadCleanup(ThreadVars *tv)
+{
+ StatsPublicThreadContextCleanup(&tv->perf_public_ctx);
+ StatsReleasePrivateThreadContext(&tv->perf_private_ctx);
+}
+
/*----------------------------------Unit_Tests--------------------------------*/
#ifdef UNITTESTS
int StatsUpdateCounterArray(StatsPrivateThreadContext *, StatsPublicThreadContext *);
uint64_t StatsGetLocalCounterValue(struct ThreadVars_ *, uint16_t);
int StatsSetupPrivate(struct ThreadVars_ *);
+void StatsThreadCleanup(struct ThreadVars_ *);
#define StatsSyncCounters(tv) \
StatsUpdateCounterArray(&(tv)->perf_private_ctx, &(tv)->perf_public_ctx); \
SCLogDebug("Freeing thread '%s'.", tv->name);
- SCMutexDestroy(&tv->perf_public_ctx.m);
+ StatsThreadCleanup(tv);
s = (TmSlot *)tv->tm_slots;
while (s) {