#include "source-lib.h"
#include "threadvars.h"
+static int worker_id = 1;
+
/**
* Suricata worker thread in library mode.
* The functions should be wrapped in an API layer.
char *pcap_file = (char *)arg;
/* Create worker. */
- ThreadVars *tv = SCRunModeLibCreateThreadVars();
+ ThreadVars *tv = SCRunModeLibCreateThreadVars(worker_id++);
if (!tv) {
pthread_exit(NULL);
}
#include "runmode-lib.h"
#include "runmodes.h"
#include "tm-threads.h"
-#include "util-device.h"
-
-static int g_thread_id = 0;
/** \brief register runmodes for suricata as a library */
void RunModeIdsLibRegister(void)
return "live";
}
-ThreadVars *SCRunModeLibCreateThreadVars(void)
+ThreadVars *SCRunModeLibCreateThreadVars(int worker_id)
{
char tname[TM_THREAD_NAME_MAX];
TmModule *tm_module = NULL;
- snprintf(tname, sizeof(tname), "%s#%02d", thread_name_workers, ++g_thread_id);
+ snprintf(tname, sizeof(tname), "%s#%02d", thread_name_workers, worker_id);
ThreadVars *tv = TmThreadCreatePacketHandler(
tname, "packetpool", "packetpool", "packetpool", "packetpool", "lib");
}
tv->stream_pq = NULL;
- --g_thread_id;
SCLogDebug("%s ending", tv->name);
TmThreadsSetFlag(tv, THV_CLOSED);
}
* Unlike other runmodes, this does not spawn a thread, as the threads
* are controlled by the application using Suricata as a library.
*
+ * \param worker_id an ID to give this ThreadVars instance
+ *
* \return Pointer to allocated ThreadVars or NULL on failure
*/
-ThreadVars *SCRunModeLibCreateThreadVars(void);
+ThreadVars *SCRunModeLibCreateThreadVars(int worker_id);
/** \brief start the "fake" worker.
*