util-affinity: export CPU set parsing function

pull/3221/head
Eric Leblond 7 years ago
parent 2598078ee6
commit ac5957d461

@ -95,7 +95,9 @@ static void AffinitySetupInit(void)
return; return;
} }
static void BuildCpuset(const char *name, ConfNode *node, cpu_set_t *cpu) void BuildCpusetWithCallback(const char *name, ConfNode *node,
void (*Callback)(int i, void * data),
void *data)
{ {
ConfNode *lnode; ConfNode *lnode;
TAILQ_FOREACH(lnode, &node->head, next) { TAILQ_FOREACH(lnode, &node->head, next) {
@ -152,12 +154,22 @@ static void BuildCpuset(const char *name, ConfNode *node, cpu_set_t *cpu)
b = a; b = a;
} }
for (i = a; i<= b; i++) { for (i = a; i<= b; i++) {
CPU_SET(i, cpu); Callback(i, data);
} }
if (stop) if (stop)
break; break;
} }
} }
static void AffinityCallback(int i, void *data)
{
CPU_SET(i, (cpu_set_t *)data);
}
static void BuildCpuset(const char *name, ConfNode *node, cpu_set_t *cpu)
{
BuildCpusetWithCallback(name, node, AffinityCallback, (void *) cpu);
}
#endif /* OS_WIN32 and __OpenBSD__ */ #endif /* OS_WIN32 and __OpenBSD__ */
/** /**

@ -24,6 +24,7 @@
#ifndef __UTIL_AFFINITY_H__ #ifndef __UTIL_AFFINITY_H__
#define __UTIL_AFFINITY_H__ #define __UTIL_AFFINITY_H__
#include "suricata-common.h" #include "suricata-common.h"
#include "conf.h"
#if defined OS_FREEBSD #if defined OS_FREEBSD
#include <sched.h> #include <sched.h>
@ -86,4 +87,8 @@ ThreadsAffinityType * GetAffinityTypeFromName(const char *name);
int AffinityGetNextCPU(ThreadsAffinityType *taf); int AffinityGetNextCPU(ThreadsAffinityType *taf);
void BuildCpusetWithCallback(const char *name, ConfNode *node,
void (*Callback)(int i, void * data),
void *data);
#endif /* __UTIL_AFFINITY_H__ */ #endif /* __UTIL_AFFINITY_H__ */

Loading…
Cancel
Save