Unify the use of slots to a single struct for threading API. Remove separate slot append functions for 1slot and varslot

remotes/origin/master-1.1.x
Anoop Saldanha 14 years ago committed by Victor Julien
parent 6730c3ace1
commit 4f7df1029d

@ -308,7 +308,7 @@ static void SCCudaPBQueueBuffer(SCCudaPBThreadCtx *tctx)
void *SCCudaPBTmThreadsSlot1(void *td)
{
ThreadVars *tv = (ThreadVars *)td;
Tm1Slot *s = (Tm1Slot *)tv->tm_slots;
TmSlot *s = (TmSlot *)tv->tm_slots;
Packet *p = NULL;
char run = 1;
TmEcode r = TM_ECODE_OK;
@ -322,8 +322,8 @@ void *SCCudaPBTmThreadsSlot1(void *td)
SCLogDebug("%s starting", tv->name);
if (s->s.SlotThreadInit != NULL) {
r = s->s.SlotThreadInit(tv, s->s.slot_initdata, &s->s.slot_data);
if (s->SlotThreadInit != NULL) {
r = s->SlotThreadInit(tv, s->slot_initdata, &s->slot_data);
if (r != TM_ECODE_OK) {
EngineKill();
@ -331,8 +331,8 @@ void *SCCudaPBTmThreadsSlot1(void *td)
pthread_exit((void *) -1);
}
}
memset(&s->s.slot_pre_pq, 0, sizeof(PacketQueue));
memset(&s->s.slot_post_pq, 0, sizeof(PacketQueue));
memset(&s->slot_pre_pq, 0, sizeof(PacketQueue));
memset(&s->slot_post_pq, 0, sizeof(PacketQueue));
TmThreadsSetFlag(tv, THV_INIT_DONE);
while(run) {
@ -352,9 +352,9 @@ void *SCCudaPBTmThreadsSlot1(void *td)
* the Batcher TM(which is waiting on a cond from the previous
* feeder TM). Please handle the NULL packet case in the
* function that you now call */
r = s->s.SlotFunc(tv, p, s->s.slot_data, NULL, NULL);
r = s->SlotFunc(tv, p, s->slot_data, NULL, NULL);
} else {
r = s->s.SlotFunc(tv, p, s->s.slot_data, NULL, NULL);
r = s->SlotFunc(tv, p, s->slot_data, NULL, NULL);
/* handle error */
if (r == TM_ECODE_FAILED) {
TmqhOutputPacketpool(tv, p);
@ -372,12 +372,12 @@ void *SCCudaPBTmThreadsSlot1(void *td)
}
}
if (s->s.SlotThreadExitPrintStats != NULL) {
s->s.SlotThreadExitPrintStats(tv, s->s.slot_data);
if (s->SlotThreadExitPrintStats != NULL) {
s->SlotThreadExitPrintStats(tv, s->slot_data);
}
if (s->s.SlotThreadDeinit != NULL) {
r = s->s.SlotThreadDeinit(tv, s->s.slot_data);
if (s->SlotThreadDeinit != NULL) {
r = s->SlotThreadDeinit(tv, s->slot_data);
if (r != TM_ECODE_OK) {
TmThreadsSetFlag(tv, THV_CLOSED);
pthread_exit((void *) -1);

@ -100,7 +100,7 @@ int RunModeErfDagAuto(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName failed for ReceiveErfDag\n");
exit(EXIT_FAILURE);
}
Tm1SlotSetFunc(tv_receiveerf, tm_module, iface);
TmSlotSetFuncAppend(tv_receiveerf, tm_module, iface);
if (threading_set_cpu_affinity) {
TmThreadSetCPUAffinity(tv_receiveerf, 0);
@ -127,14 +127,14 @@ int RunModeErfDagAuto(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName DecodeErfDag failed\n");
exit(EXIT_FAILURE);
}
TmVarSlotSetFuncAppend(tv_decode1, tm_module, NULL);
TmSlotSetFuncAppend(tv_decode1, tm_module, NULL);
tm_module = TmModuleGetByName("StreamTcp");
if (tm_module == NULL) {
printf("ERROR: TmModuleGetByName StreamTcp failed\n");
exit(EXIT_FAILURE);
}
TmVarSlotSetFuncAppend(tv_decode1, tm_module, NULL);
TmSlotSetFuncAppend(tv_decode1, tm_module, NULL);
if (threading_set_cpu_affinity) {
TmThreadSetCPUAffinity(tv_decode1, 0);
@ -180,7 +180,7 @@ int RunModeErfDagAuto(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName Detect failed\n");
exit(EXIT_FAILURE);
}
Tm1SlotSetFunc(tv_detect_ncpu, tm_module, (void *)de_ctx);
TmSlotSetFuncAppend(tv_detect_ncpu, tm_module, (void *)de_ctx);
if (threading_set_cpu_affinity) {
TmThreadSetCPUAffinity(tv_detect_ncpu, (int)cpu);

@ -89,7 +89,7 @@ int RunModeErfFileAuto(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName failed for ReceiveErfFile\n");
exit(EXIT_FAILURE);
}
Tm1SlotSetFunc(tv_receiveerf, tm_module, file);
TmSlotSetFuncAppend(tv_receiveerf, tm_module, file);
if (threading_set_cpu_affinity) {
TmThreadSetCPUAffinity(tv_receiveerf, 0);
@ -116,14 +116,14 @@ int RunModeErfFileAuto(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName DecodeErfFile failed\n");
exit(EXIT_FAILURE);
}
TmVarSlotSetFuncAppend(tv_decode1, tm_module, NULL);
TmSlotSetFuncAppend(tv_decode1, tm_module, NULL);
tm_module = TmModuleGetByName("StreamTcp");
if (tm_module == NULL) {
printf("ERROR: TmModuleGetByName StreamTcp failed\n");
exit(EXIT_FAILURE);
}
TmVarSlotSetFuncAppend(tv_decode1, tm_module, NULL);
TmSlotSetFuncAppend(tv_decode1, tm_module, NULL);
if (threading_set_cpu_affinity) {
TmThreadSetCPUAffinity(tv_decode1, 0);
@ -169,7 +169,7 @@ int RunModeErfFileAuto(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName Detect failed\n");
exit(EXIT_FAILURE);
}
Tm1SlotSetFunc(tv_detect_ncpu, tm_module, (void *)de_ctx);
TmSlotSetFuncAppend(tv_detect_ncpu, tm_module, (void *)de_ctx);
if (threading_set_cpu_affinity) {
TmThreadSetCPUAffinity(tv_detect_ncpu, (int)cpu);

@ -101,7 +101,7 @@ int RunModeIpsIPFWAuto(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName failed for ReceiveIPFW\n");
exit(EXIT_FAILURE);
}
Tm1SlotSetFunc(tv_receiveipfw, tm_module, NULL);
TmSlotSetFuncAppend(tv_receiveipfw, tm_module, NULL);
if (threading_set_cpu_affinity) {
TmThreadSetCPUAffinity(tv_receiveipfw, 0);
@ -128,7 +128,7 @@ int RunModeIpsIPFWAuto(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName DecodeIPFW failed\n");
exit(EXIT_FAILURE);
}
Tm1SlotSetFunc(tv_decode1, tm_module, NULL);
TmSlotSetFuncAppend(tv_decode1, tm_module, NULL);
if (threading_set_cpu_affinity) {
TmThreadSetCPUAffinity(tv_decode1, 0);
@ -155,7 +155,7 @@ int RunModeIpsIPFWAuto(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName StreamTcp failed\n");
exit(EXIT_FAILURE);
}
Tm1SlotSetFunc(tv_stream1, tm_module, NULL);
TmSlotSetFuncAppend(tv_stream1, tm_module, NULL);
if (threading_set_cpu_affinity) {
TmThreadSetCPUAffinity(tv_stream1, 0);
@ -201,7 +201,7 @@ int RunModeIpsIPFWAuto(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName Detect failed\n");
exit(EXIT_FAILURE);
}
Tm1SlotSetFunc(tv_detect_ncpu, tm_module, (void *)de_ctx);
TmSlotSetFuncAppend(tv_detect_ncpu, tm_module, (void *)de_ctx);
if (threading_set_cpu_affinity) {
TmThreadSetCPUAffinity(tv_detect_ncpu, (int)cpu);
@ -248,7 +248,7 @@ int RunModeIpsIPFWAuto(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName VerdictIPFW failed\n");
exit(EXIT_FAILURE);
}
Tm1SlotSetFunc(tv_verdict, tm_module, NULL);
TmSlotSetFuncAppend(tv_verdict, tm_module, NULL);
if (threading_set_cpu_affinity) {
TmThreadSetCPUAffinity(tv_verdict, 0);
@ -275,7 +275,7 @@ int RunModeIpsIPFWAuto(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName for RespondReject failed\n");
exit(EXIT_FAILURE);
}
Tm1SlotSetFunc(tv_rreject, tm_module, NULL);
TmSlotSetFuncAppend(tv_rreject, tm_module, NULL);
if (threading_set_cpu_affinity) {
TmThreadSetCPUAffinity(tv_rreject, 0);

@ -119,7 +119,7 @@ int RunModeIpsNFQAuto(DetectEngineCtx *de_ctx)
exit(EXIT_FAILURE);
}
Tm1SlotSetFunc(tv_receivenfq, tm_module, (void *) NFQGetThread(i));
TmSlotSetFuncAppend(tv_receivenfq, tm_module, (void *) NFQGetThread(i));
TmThreadSetCPU(tv_receivenfq, RECEIVE_CPU_SET);
@ -145,14 +145,14 @@ int RunModeIpsNFQAuto(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName DecodeNFQ failed\n");
exit(EXIT_FAILURE);
}
TmVarSlotSetFuncAppend(tv_decode,tm_module,NULL);
TmSlotSetFuncAppend(tv_decode,tm_module,NULL);
tm_module = TmModuleGetByName("StreamTcp");
if (tm_module == NULL) {
printf("ERROR: TmModuleGetByName StreamTcp failed\n");
exit(EXIT_FAILURE);
}
TmVarSlotSetFuncAppend(tv_decode, tm_module, NULL);
TmSlotSetFuncAppend(tv_decode, tm_module, NULL);
TmThreadSetCPU(tv_decode, DECODE_CPU_SET);
@ -190,7 +190,7 @@ int RunModeIpsNFQAuto(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName Detect failed\n");
exit(EXIT_FAILURE);
}
Tm1SlotSetFunc(tv_detect_ncpu, tm_module, (void *)de_ctx);
TmSlotSetFuncAppend(tv_detect_ncpu, tm_module, (void *)de_ctx);
TmThreadSetCPU(tv_detect_ncpu, DETECT_CPU_SET);
@ -231,14 +231,14 @@ int RunModeIpsNFQAuto(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName VerdictNFQ failed\n");
exit(EXIT_FAILURE);
}
TmVarSlotSetFuncAppend(tv_verdict, tm_module, (void *)NFQGetThread(i));
TmSlotSetFuncAppend(tv_verdict, tm_module, (void *)NFQGetThread(i));
tm_module = TmModuleGetByName("RespondReject");
if (tm_module == NULL) {
printf("ERROR: TmModuleGetByName for RespondReject failed\n");
exit(EXIT_FAILURE);
}
TmVarSlotSetFuncAppend(tv_verdict, tm_module, NULL);
TmSlotSetFuncAppend(tv_verdict, tm_module, NULL);
TmThreadSetCPU(tv_verdict, VERDICT_CPU_SET);

@ -93,28 +93,28 @@ int RunModeFilePcap2(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName failed for ReceivePcap\n");
exit(EXIT_FAILURE);
}
TmVarSlotSetFuncAppend(tv, tm_module, file);
TmSlotSetFuncAppend(tv, tm_module, file);
tm_module = TmModuleGetByName("DecodePcapFile");
if (tm_module == NULL) {
printf("ERROR: TmModuleGetByName DecodePcap failed\n");
exit(EXIT_FAILURE);
}
TmVarSlotSetFuncAppend(tv, tm_module, NULL);
TmSlotSetFuncAppend(tv, tm_module, NULL);
tm_module = TmModuleGetByName("StreamTcp");
if (tm_module == NULL) {
printf("ERROR: TmModuleGetByName StreamTcp failed\n");
exit(EXIT_FAILURE);
}
TmVarSlotSetFuncAppend(tv, tm_module, NULL);
TmSlotSetFuncAppend(tv, tm_module, NULL);
tm_module = TmModuleGetByName("Detect");
if (tm_module == NULL) {
printf("ERROR: TmModuleGetByName Detect failed\n");
exit(EXIT_FAILURE);
}
TmVarSlotSetFuncAppend(tv, tm_module, (void *)de_ctx);
TmSlotSetFuncAppend(tv, tm_module, (void *)de_ctx);
SetupOutputs(tv);
@ -178,7 +178,7 @@ int RunModeFilePcapAuto(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName failed for ReceivePcap\n");
exit(EXIT_FAILURE);
}
Tm1SlotSetFunc(tv_receivepcap, tm_module, file);
TmSlotSetFuncAppend(tv_receivepcap, tm_module, file);
TmThreadSetCPU(tv_receivepcap, RECEIVE_CPU_SET);
@ -203,7 +203,7 @@ int RunModeFilePcapAuto(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName DecodePcap failed\n");
exit(EXIT_FAILURE);
}
Tm1SlotSetFunc(tv_decode1, tm_module, NULL);
TmSlotSetFuncAppend(tv_decode1, tm_module, NULL);
TmThreadSetCPU(tv_decode1, DECODE_CPU_SET);
@ -228,7 +228,7 @@ int RunModeFilePcapAuto(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName CudaPacketBatcher failed\n");
exit(EXIT_FAILURE);
}
Tm1SlotSetFunc(tv_cuda_PB, tm_module, (void *)de_ctx);
TmSlotSetFuncAppend(tv_cuda_PB, tm_module, (void *)de_ctx);
TmThreadSetCPU(tv_cuda_PB, DETECT_CPU_SET);
@ -251,7 +251,7 @@ int RunModeFilePcapAuto(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName StreamTcp failed\n");
exit(EXIT_FAILURE);
}
Tm1SlotSetFunc(tv_stream1, tm_module, NULL);
TmSlotSetFuncAppend(tv_stream1, tm_module, NULL);
TmThreadSetCPU(tv_stream1, STREAM_CPU_SET);
@ -274,14 +274,14 @@ int RunModeFilePcapAuto(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName DecodePcap failed\n");
exit(EXIT_FAILURE);
}
TmVarSlotSetFuncAppend(tv_decode1, tm_module, NULL);
TmSlotSetFuncAppend(tv_decode1, tm_module, NULL);
tm_module = TmModuleGetByName("StreamTcp");
if (tm_module == NULL) {
printf("ERROR: TmModuleGetByName StreamTcp failed\n");
exit(EXIT_FAILURE);
}
TmVarSlotSetFuncAppend(tv_decode1, tm_module, NULL);
TmSlotSetFuncAppend(tv_decode1, tm_module, NULL);
TmThreadSetCPU(tv_decode1, DECODE_CPU_SET);
@ -306,14 +306,14 @@ int RunModeFilePcapAuto(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName DecodePcap failed\n");
exit(EXIT_FAILURE);
}
TmVarSlotSetFuncAppend(tv_decode1, tm_module, NULL);
TmSlotSetFuncAppend(tv_decode1, tm_module, NULL);
tm_module = TmModuleGetByName("StreamTcp");
if (tm_module == NULL) {
printf("ERROR: TmModuleGetByName StreamTcp failed\n");
exit(EXIT_FAILURE);
}
TmVarSlotSetFuncAppend(tv_decode1, tm_module, NULL);
TmSlotSetFuncAppend(tv_decode1, tm_module, NULL);
TmThreadSetCPU(tv_decode1, DECODE_CPU_SET);
@ -356,7 +356,7 @@ int RunModeFilePcapAuto(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName Detect failed\n");
exit(EXIT_FAILURE);
}
Tm1SlotSetFunc(tv_detect_ncpu, tm_module, (void *)de_ctx);
TmSlotSetFuncAppend(tv_detect_ncpu, tm_module, (void *)de_ctx);
TmThreadSetCPU(tv_detect_ncpu, DETECT_CPU_SET);
@ -476,14 +476,14 @@ int RunModeFilePcapAutoFp(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName failed for ReceivePcap\n");
exit(EXIT_FAILURE);
}
TmVarSlotSetFuncAppend(tv_receivepcap, tm_module, file);
TmSlotSetFuncAppend(tv_receivepcap, tm_module, file);
tm_module = TmModuleGetByName("DecodePcapFile");
if (tm_module == NULL) {
printf("ERROR: TmModuleGetByName DecodePcap failed\n");
exit(EXIT_FAILURE);
}
TmVarSlotSetFuncAppend(tv_receivepcap, tm_module, NULL);
TmSlotSetFuncAppend(tv_receivepcap, tm_module, NULL);
if (threading_set_cpu_affinity) {
TmThreadSetCPUAffinity(tv_receivepcap, 0);
@ -519,14 +519,14 @@ int RunModeFilePcapAutoFp(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName StreamTcp failed\n");
exit(EXIT_FAILURE);
}
TmVarSlotSetFuncAppend(tv_detect_ncpu, tm_module, NULL);
TmSlotSetFuncAppend(tv_detect_ncpu, tm_module, NULL);
tm_module = TmModuleGetByName("Detect");
if (tm_module == NULL) {
printf("ERROR: TmModuleGetByName Detect failed\n");
exit(EXIT_FAILURE);
}
TmVarSlotSetFuncAppend(tv_detect_ncpu, tm_module, (void *)de_ctx);
TmSlotSetFuncAppend(tv_detect_ncpu, tm_module, (void *)de_ctx);
if (threading_set_cpu_affinity) {
TmThreadSetCPUAffinity(tv_detect_ncpu, (int)cpu);

@ -115,7 +115,7 @@ int RunModeIdsPcapAuto(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName failed for ReceivePcap\n");
exit(EXIT_FAILURE);
}
Tm1SlotSetFunc(tv_receivepcap, tm_module, (void *)pcap_devc);
TmSlotSetFuncAppend(tv_receivepcap, tm_module, (void *)pcap_devc);
TmThreadSetCPU(tv_receivepcap, RECEIVE_CPU_SET);
@ -153,7 +153,7 @@ int RunModeIdsPcapAuto(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName failed for ReceivePcap\n");
exit(EXIT_FAILURE);
}
Tm1SlotSetFunc(tv_receivepcap, tm_module, (void *)pcap_devc);
TmSlotSetFuncAppend(tv_receivepcap, tm_module, (void *)pcap_devc);
TmThreadSetCPU(tv_receivepcap, RECEIVE_CPU_SET);
@ -180,7 +180,7 @@ int RunModeIdsPcapAuto(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName DecodePcap failed\n");
exit(EXIT_FAILURE);
}
Tm1SlotSetFunc(tv_decode1, tm_module, NULL);
TmSlotSetFuncAppend(tv_decode1, tm_module, NULL);
TmThreadSetCPU(tv_decode1, DECODE_CPU_SET);
@ -205,7 +205,7 @@ int RunModeIdsPcapAuto(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName CudaPacketBatcher failed\n");
exit(EXIT_FAILURE);
}
Tm1SlotSetFunc(tv_cuda_PB, tm_module, (void *)de_ctx);
TmSlotSetFuncAppend(tv_cuda_PB, tm_module, (void *)de_ctx);
TmThreadSetCPU(tv_cuda_PB, DETECT_CPU_SET);
@ -228,7 +228,7 @@ int RunModeIdsPcapAuto(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName StreamTcp failed\n");
exit(EXIT_FAILURE);
}
Tm1SlotSetFunc(tv_stream1, tm_module, NULL);
TmSlotSetFuncAppend(tv_stream1, tm_module, NULL);
TmThreadSetCPU(tv_stream1, STREAM_CPU_SET);
@ -251,14 +251,14 @@ int RunModeIdsPcapAuto(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName DecodePcap failed\n");
exit(EXIT_FAILURE);
}
TmVarSlotSetFuncAppend(tv_decode1, tm_module, NULL);
TmSlotSetFuncAppend(tv_decode1, tm_module, NULL);
tm_module = TmModuleGetByName("StreamTcp");
if (tm_module == NULL) {
printf("ERROR: TmModuleGetByName StreamTcp failed\n");
exit(EXIT_FAILURE);
}
TmVarSlotSetFuncAppend(tv_decode1, tm_module, NULL);
TmSlotSetFuncAppend(tv_decode1, tm_module, NULL);
TmThreadSetCPU(tv_decode1, DECODE_CPU_SET);
@ -283,14 +283,14 @@ int RunModeIdsPcapAuto(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName DecodePcap failed\n");
exit(EXIT_FAILURE);
}
TmVarSlotSetFuncAppend(tv_decode1, tm_module, NULL);
TmSlotSetFuncAppend(tv_decode1, tm_module, NULL);
tm_module = TmModuleGetByName("StreamTcp");
if (tm_module == NULL) {
printf("ERROR: TmModuleGetByName StreamTcp failed\n");
exit(EXIT_FAILURE);
}
TmVarSlotSetFuncAppend(tv_decode1, tm_module, NULL);
TmSlotSetFuncAppend(tv_decode1, tm_module, NULL);
TmThreadSetCPU(tv_decode1, DECODE_CPU_SET);
@ -332,7 +332,7 @@ int RunModeIdsPcapAuto(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName Detect failed\n");
exit(EXIT_FAILURE);
}
Tm1SlotSetFunc(tv_detect_ncpu, tm_module, (void *)de_ctx);
TmSlotSetFuncAppend(tv_detect_ncpu, tm_module, (void *)de_ctx);
TmThreadSetCPU(tv_detect_ncpu, DETECT_CPU_SET);
@ -368,7 +368,7 @@ int RunModeIdsPcapAuto(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName for RespondReject failed\n");
exit(EXIT_FAILURE);
}
Tm1SlotSetFunc(tv_rreject, tm_module, NULL);
TmSlotSetFuncAppend(tv_rreject, tm_module, NULL);
TmThreadSetCPU(tv_rreject, REJECT_CPU_SET);

@ -120,7 +120,7 @@ int RunModeIdsPfringAuto(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName failed for ReceivePfring\n");
exit(EXIT_FAILURE);
}
Tm1SlotSetFunc(tv_receivepfring, tm_module, NULL);
TmSlotSetFuncAppend(tv_receivepfring, tm_module, NULL);
if (threading_set_cpu_affinity) {
TmThreadSetCPUAffinity(tv_receivepfring, 0);
@ -147,7 +147,7 @@ int RunModeIdsPfringAuto(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName DecodePfring failed\n");
exit(EXIT_FAILURE);
}
Tm1SlotSetFunc(tv_decode1, tm_module, NULL);
TmSlotSetFuncAppend(tv_decode1, tm_module, NULL);
if (threading_set_cpu_affinity) {
TmThreadSetCPUAffinity(tv_decode1, 0);
@ -174,7 +174,7 @@ int RunModeIdsPfringAuto(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName StreamTcp failed\n");
exit(EXIT_FAILURE);
}
Tm1SlotSetFunc(tv_stream1, tm_module, NULL);
TmSlotSetFuncAppend(tv_stream1, tm_module, NULL);
if (threading_set_cpu_affinity) {
TmThreadSetCPUAffinity(tv_stream1, 0);
@ -220,7 +220,7 @@ int RunModeIdsPfringAuto(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName Detect failed\n");
exit(EXIT_FAILURE);
}
Tm1SlotSetFunc(tv_detect_ncpu, tm_module, (void *)de_ctx);
TmSlotSetFuncAppend(tv_detect_ncpu, tm_module, (void *)de_ctx);
if (threading_set_cpu_affinity) {
TmThreadSetCPUAffinity(tv_detect_ncpu, (int)cpu);
@ -267,7 +267,7 @@ int RunModeIdsPfringAuto(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName for RespondReject failed\n");
exit(EXIT_FAILURE);
}
Tm1SlotSetFunc(tv_rreject, tm_module, NULL);
TmSlotSetFuncAppend(tv_rreject, tm_module, NULL);
if (threading_set_cpu_affinity) {
TmThreadSetCPUAffinity(tv_rreject, 0);
@ -370,14 +370,14 @@ int RunModeIdsPfringAutoFp(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName failed for ReceivePfring\n");
exit(EXIT_FAILURE);
}
TmVarSlotSetFuncAppend(tv_receive, tm_module, NULL);
TmSlotSetFuncAppend(tv_receive, tm_module, NULL);
tm_module = TmModuleGetByName("DecodePfring");
if (tm_module == NULL) {
printf("ERROR: TmModuleGetByName DecodePfring failed\n");
exit(EXIT_FAILURE);
}
TmVarSlotSetFuncAppend(tv_receive, tm_module, NULL);
TmSlotSetFuncAppend(tv_receive, tm_module, NULL);
if (threading_set_cpu_affinity) {
TmThreadSetCPUAffinity(tv_receive, 0);
@ -414,14 +414,14 @@ int RunModeIdsPfringAutoFp(DetectEngineCtx *de_ctx)
printf("ERROR: TmModuleGetByName StreamTcp failed\n");
exit(EXIT_FAILURE);
}
TmVarSlotSetFuncAppend(tv_detect_ncpu, tm_module, NULL);
TmSlotSetFuncAppend(tv_detect_ncpu, tm_module, NULL);
tm_module = TmModuleGetByName("Detect");
if (tm_module == NULL) {
printf("ERROR: TmModuleGetByName Detect failed\n");
exit(EXIT_FAILURE);
}
TmVarSlotSetFuncAppend(tv_detect_ncpu, tm_module, (void *)de_ctx);
TmSlotSetFuncAppend(tv_detect_ncpu, tm_module, (void *)de_ctx);
if (threading_set_cpu_affinity) {
TmThreadSetCPUAffinity(tv_detect_ncpu, (int)cpu);

@ -383,7 +383,7 @@ void SetupOutputs(ThreadVars *tv)
RunModeOutput *output;
TAILQ_FOREACH(output, &RunModeOutputs, entries) {
tv->cap_flags |= output->tm_module->cap_flags;
TmVarSlotSetFuncAppend(tv, output->tm_module, output->output_ctx);
TmSlotSetFuncAppend(tv, output->tm_module, output->output_ctx);
}
}

@ -30,6 +30,8 @@
#include "counters.h"
#include "threads.h"
struct TmSlot_;
/** Thread flags set and read by threads to control the threads */
#define THV_USE 0x01 /** thread is in use */
#define THV_INIT_DONE 0x02 /** thread initialization done */
@ -76,7 +78,7 @@ typedef struct ThreadVars_ {
/** slot functions */
void *(*tm_func)(void *);
void *tm_slots;
struct TmSlot_ *tm_slots;
uint8_t thread_setup_flags;
uint16_t cpu_affinity; /** cpu or core number to set affinity to */

@ -100,7 +100,7 @@ void TmThreadsUnsetFlag(ThreadVars *tv, uint8_t flag) {
void *TmThreadsSlot1NoIn(void *td) {
ThreadVars *tv = (ThreadVars *)td;
Tm1Slot *s = (Tm1Slot *)tv->tm_slots;
TmSlot *s = (TmSlot *)tv->tm_slots;
Packet *p = NULL;
char run = 1;
TmEcode r = TM_ECODE_OK;
@ -114,8 +114,8 @@ void *TmThreadsSlot1NoIn(void *td) {
if (tv->thread_setup_flags != 0)
TmThreadSetupOptions(tv);
if (s->s.SlotThreadInit != NULL) {
r = s->s.SlotThreadInit(tv, s->s.slot_initdata, &s->s.slot_data);
if (s->SlotThreadInit != NULL) {
r = s->SlotThreadInit(tv, s->slot_initdata, &s->slot_data);
if (r != TM_ECODE_OK) {
EngineKill();
@ -123,19 +123,19 @@ void *TmThreadsSlot1NoIn(void *td) {
pthread_exit((void *) -1);
}
}
memset(&s->s.slot_pre_pq, 0, sizeof(PacketQueue));
memset(&s->s.slot_post_pq, 0, sizeof(PacketQueue));
memset(&s->slot_pre_pq, 0, sizeof(PacketQueue));
memset(&s->slot_post_pq, 0, sizeof(PacketQueue));
TmThreadsSetFlag(tv, THV_INIT_DONE);
while(run) {
TmThreadTestThreadUnPaused(tv);
r = s->s.SlotFunc(tv, p, s->s.slot_data, &s->s.slot_pre_pq, &s->s.slot_post_pq);
r = s->SlotFunc(tv, p, s->slot_data, &s->slot_pre_pq, &s->slot_post_pq);
/* handle error */
if (r == TM_ECODE_FAILED) {
TmqhReleasePacketsToPacketPool(&s->s.slot_pre_pq);
TmqhReleasePacketsToPacketPool(&s->s.slot_post_pq);
TmqhReleasePacketsToPacketPool(&s->slot_pre_pq);
TmqhReleasePacketsToPacketPool(&s->slot_post_pq);
if (p != NULL)
TmqhOutputPacketpool(tv, p);
TmThreadsSetFlag(tv, THV_FAILED);
@ -143,8 +143,8 @@ void *TmThreadsSlot1NoIn(void *td) {
}
/* handle pre queue */
while (s->s.slot_pre_pq.top != NULL) {
Packet *extra_p = PacketDequeue(&s->s.slot_pre_pq);
while (s->slot_pre_pq.top != NULL) {
Packet *extra_p = PacketDequeue(&s->slot_pre_pq);
if (extra_p != NULL) {
tv->tmqh_out(tv, extra_p);
}
@ -155,8 +155,8 @@ void *TmThreadsSlot1NoIn(void *td) {
tv->tmqh_out(tv, p);
/* handle post queue */
while (s->s.slot_post_pq.top != NULL) {
Packet *extra_p = PacketDequeue(&s->s.slot_post_pq);
while (s->slot_post_pq.top != NULL) {
Packet *extra_p = PacketDequeue(&s->slot_post_pq);
if (extra_p != NULL) {
tv->tmqh_out(tv, extra_p);
}
@ -168,12 +168,12 @@ void *TmThreadsSlot1NoIn(void *td) {
}
}
if (s->s.SlotThreadExitPrintStats != NULL) {
s->s.SlotThreadExitPrintStats(tv, s->s.slot_data);
if (s->SlotThreadExitPrintStats != NULL) {
s->SlotThreadExitPrintStats(tv, s->slot_data);
}
if (s->s.SlotThreadDeinit != NULL) {
r = s->s.SlotThreadDeinit(tv, s->s.slot_data);
if (s->SlotThreadDeinit != NULL) {
r = s->SlotThreadDeinit(tv, s->slot_data);
if (r != TM_ECODE_OK) {
TmThreadsSetFlag(tv, THV_CLOSED);
pthread_exit((void *) -1);
@ -186,7 +186,7 @@ void *TmThreadsSlot1NoIn(void *td) {
void *TmThreadsSlot1NoOut(void *td) {
ThreadVars *tv = (ThreadVars *)td;
Tm1Slot *s = (Tm1Slot *)tv->tm_slots;
TmSlot *s = (TmSlot *)tv->tm_slots;
Packet *p = NULL;
char run = 1;
TmEcode r = TM_ECODE_OK;
@ -200,8 +200,8 @@ void *TmThreadsSlot1NoOut(void *td) {
if (tv->thread_setup_flags != 0)
TmThreadSetupOptions(tv);
if (s->s.SlotThreadInit != NULL) {
r = s->s.SlotThreadInit(tv, s->s.slot_initdata, &s->s.slot_data);
if (s->SlotThreadInit != NULL) {
r = s->SlotThreadInit(tv, s->slot_initdata, &s->slot_data);
if (r != TM_ECODE_OK) {
EngineKill();
@ -209,8 +209,8 @@ void *TmThreadsSlot1NoOut(void *td) {
pthread_exit((void *) -1);
}
}
memset(&s->s.slot_pre_pq, 0, sizeof(PacketQueue));
memset(&s->s.slot_post_pq, 0, sizeof(PacketQueue));
memset(&s->slot_pre_pq, 0, sizeof(PacketQueue));
memset(&s->slot_post_pq, 0, sizeof(PacketQueue));
TmThreadsSetFlag(tv, THV_INIT_DONE);
@ -219,7 +219,7 @@ void *TmThreadsSlot1NoOut(void *td) {
p = tv->tmqh_in(tv);
r = s->s.SlotFunc(tv, p, s->s.slot_data, /* no outqh no pq */NULL, /* no outqh no pq */NULL);
r = s->SlotFunc(tv, p, s->slot_data, /* no outqh no pq */NULL, /* no outqh no pq */NULL);
/* handle error */
if (r == TM_ECODE_FAILED) {
TmqhOutputPacketpool(tv, p);
@ -233,12 +233,12 @@ void *TmThreadsSlot1NoOut(void *td) {
}
}
if (s->s.SlotThreadExitPrintStats != NULL) {
s->s.SlotThreadExitPrintStats(tv, s->s.slot_data);
if (s->SlotThreadExitPrintStats != NULL) {
s->SlotThreadExitPrintStats(tv, s->slot_data);
}
if (s->s.SlotThreadDeinit != NULL) {
r = s->s.SlotThreadDeinit(tv, s->s.slot_data);
if (s->SlotThreadDeinit != NULL) {
r = s->SlotThreadDeinit(tv, s->slot_data);
if (r != TM_ECODE_OK) {
TmThreadsSetFlag(tv, THV_CLOSED);
pthread_exit((void *) -1);
@ -251,7 +251,7 @@ void *TmThreadsSlot1NoOut(void *td) {
void *TmThreadsSlot1NoInOut(void *td) {
ThreadVars *tv = (ThreadVars *)td;
Tm1Slot *s = (Tm1Slot *)tv->tm_slots;
TmSlot *s = (TmSlot *)tv->tm_slots;
char run = 1;
TmEcode r = TM_ECODE_OK;
@ -266,8 +266,8 @@ void *TmThreadsSlot1NoInOut(void *td) {
SCLogDebug("%s starting", tv->name);
if (s->s.SlotThreadInit != NULL) {
r = s->s.SlotThreadInit(tv, s->s.slot_initdata, &s->s.slot_data);
if (s->SlotThreadInit != NULL) {
r = s->SlotThreadInit(tv, s->slot_initdata, &s->slot_data);
if (r != TM_ECODE_OK) {
EngineKill();
@ -275,15 +275,15 @@ void *TmThreadsSlot1NoInOut(void *td) {
pthread_exit((void *) -1);
}
}
memset(&s->s.slot_pre_pq, 0, sizeof(PacketQueue));
memset(&s->s.slot_post_pq, 0, sizeof(PacketQueue));
memset(&s->slot_pre_pq, 0, sizeof(PacketQueue));
memset(&s->slot_post_pq, 0, sizeof(PacketQueue));
TmThreadsSetFlag(tv, THV_INIT_DONE);
while(run) {
TmThreadTestThreadUnPaused(tv);
r = s->s.SlotFunc(tv, NULL, s->s.slot_data, /* no outqh, no pq */NULL, NULL);
r = s->SlotFunc(tv, NULL, s->slot_data, /* no outqh, no pq */NULL, NULL);
//printf("%s: TmThreadsSlot1NoInNoOut: r %" PRId32 "\n", tv->name, r);
/* handle error */
@ -299,12 +299,12 @@ void *TmThreadsSlot1NoInOut(void *td) {
}
}
if (s->s.SlotThreadExitPrintStats != NULL) {
s->s.SlotThreadExitPrintStats(tv, s->s.slot_data);
if (s->SlotThreadExitPrintStats != NULL) {
s->SlotThreadExitPrintStats(tv, s->slot_data);
}
if (s->s.SlotThreadDeinit != NULL) {
r = s->s.SlotThreadDeinit(tv, s->s.slot_data);
if (s->SlotThreadDeinit != NULL) {
r = s->SlotThreadDeinit(tv, s->slot_data);
if (r != TM_ECODE_OK) {
TmThreadsSetFlag(tv, THV_CLOSED);
pthread_exit((void *) -1);
@ -318,7 +318,7 @@ void *TmThreadsSlot1NoInOut(void *td) {
void *TmThreadsSlot1(void *td) {
ThreadVars *tv = (ThreadVars *)td;
Tm1Slot *s = (Tm1Slot *)tv->tm_slots;
TmSlot *s = (TmSlot *)tv->tm_slots;
Packet *p = NULL;
char run = 1;
TmEcode r = TM_ECODE_OK;
@ -334,8 +334,8 @@ void *TmThreadsSlot1(void *td) {
SCLogDebug("%s starting", tv->name);
if (s->s.SlotThreadInit != NULL) {
r = s->s.SlotThreadInit(tv, s->s.slot_initdata, &s->s.slot_data);
if (s->SlotThreadInit != NULL) {
r = s->SlotThreadInit(tv, s->slot_initdata, &s->slot_data);
if (r != TM_ECODE_OK) {
EngineKill();
@ -343,8 +343,8 @@ void *TmThreadsSlot1(void *td) {
pthread_exit((void *) -1);
}
}
memset(&s->s.slot_pre_pq, 0, sizeof(PacketQueue));
memset(&s->s.slot_post_pq, 0, sizeof(PacketQueue));
memset(&s->slot_pre_pq, 0, sizeof(PacketQueue));
memset(&s->slot_post_pq, 0, sizeof(PacketQueue));
TmThreadsSetFlag(tv, THV_INIT_DONE);
while(run) {
@ -356,19 +356,19 @@ void *TmThreadsSlot1(void *td) {
if (p == NULL) {
//printf("%s: TmThreadsSlot1: p == NULL\n", tv->name);
} else {
r = s->s.SlotFunc(tv, p, s->s.slot_data, &s->s.slot_pre_pq, &s->s.slot_post_pq);
r = s->SlotFunc(tv, p, s->slot_data, &s->slot_pre_pq, &s->slot_post_pq);
/* handle error */
if (r == TM_ECODE_FAILED) {
TmqhReleasePacketsToPacketPool(&s->s.slot_pre_pq);
TmqhReleasePacketsToPacketPool(&s->s.slot_post_pq);
TmqhReleasePacketsToPacketPool(&s->slot_pre_pq);
TmqhReleasePacketsToPacketPool(&s->slot_post_pq);
TmqhOutputPacketpool(tv, p);
TmThreadsSetFlag(tv, THV_FAILED);
break;
}
while (s->s.slot_pre_pq.top != NULL) {
while (s->slot_pre_pq.top != NULL) {
/* handle new packets from this func */
Packet *extra_p = PacketDequeue(&s->s.slot_pre_pq);
Packet *extra_p = PacketDequeue(&s->slot_pre_pq);
if (extra_p != NULL) {
tv->tmqh_out(tv, extra_p);
}
@ -377,9 +377,9 @@ void *TmThreadsSlot1(void *td) {
/* output the packet */
tv->tmqh_out(tv, p);
while (s->s.slot_post_pq.top != NULL) {
while (s->slot_post_pq.top != NULL) {
/* handle new packets from this func */
Packet *extra_p = PacketDequeue(&s->s.slot_post_pq);
Packet *extra_p = PacketDequeue(&s->slot_post_pq);
if (extra_p != NULL) {
tv->tmqh_out(tv, extra_p);
}
@ -393,12 +393,12 @@ void *TmThreadsSlot1(void *td) {
}
}
if (s->s.SlotThreadExitPrintStats != NULL) {
s->s.SlotThreadExitPrintStats(tv, s->s.slot_data);
if (s->SlotThreadExitPrintStats != NULL) {
s->SlotThreadExitPrintStats(tv, s->slot_data);
}
if (s->s.SlotThreadDeinit != NULL) {
r = s->s.SlotThreadDeinit(tv, s->s.slot_data);
if (s->SlotThreadDeinit != NULL) {
r = s->SlotThreadDeinit(tv, s->slot_data);
if (r != TM_ECODE_OK) {
TmThreadsSetFlag(tv, THV_CLOSED);
pthread_exit((void *) -1);
@ -467,11 +467,10 @@ static inline TmEcode TmThreadsSlotVarRun (ThreadVars *tv, Packet *p, TmSlot *sl
*/
void *TmThreadsSlotVar(void *td) {
ThreadVars *tv = (ThreadVars *)td;
TmVarSlot *s = (TmVarSlot *)tv->tm_slots;
TmSlot *s = (TmSlot *)tv->tm_slots;
Packet *p = NULL;
char run = 1;
TmEcode r = TM_ECODE_OK;
TmSlot *slot = NULL;
/* Set the thread name */
SCSetThreadName(tv->name);
@ -483,16 +482,16 @@ void *TmThreadsSlotVar(void *td) {
TmThreadSetupOptions(tv);
/* check if we are setup properly */
if (s == NULL || s->s == NULL || tv->tmqh_in == NULL || tv->tmqh_out == NULL) {
if (s == NULL || tv->tmqh_in == NULL || tv->tmqh_out == NULL) {
EngineKill();
TmThreadsSetFlag(tv, THV_CLOSED);
pthread_exit((void *) -1);
}
for (slot = s->s; slot != NULL; slot = slot->slot_next) {
if (slot->SlotThreadInit != NULL) {
r = slot->SlotThreadInit(tv, slot->slot_initdata, &slot->slot_data);
for (; s != NULL; s = s->slot_next) {
if (s->SlotThreadInit != NULL) {
r = s->SlotThreadInit(tv, s->slot_initdata, &s->slot_data);
if (r != TM_ECODE_OK) {
EngineKill();
@ -500,12 +499,14 @@ void *TmThreadsSlotVar(void *td) {
pthread_exit((void *) -1);
}
}
memset(&slot->slot_pre_pq, 0, sizeof(PacketQueue));
memset(&slot->slot_post_pq, 0, sizeof(PacketQueue));
memset(&s->slot_pre_pq, 0, sizeof(PacketQueue));
memset(&s->slot_post_pq, 0, sizeof(PacketQueue));
}
TmThreadsSetFlag(tv, THV_INIT_DONE);
s = (TmSlot *)tv->tm_slots;
while(run) {
TmThreadTestThreadUnPaused(tv);
@ -514,7 +515,7 @@ void *TmThreadsSlotVar(void *td) {
if (p != NULL) {
/* run the thread module(s) */
r = TmThreadsSlotVarRun(tv, p, s->s);
r = TmThreadsSlotVarRun(tv, p, s);
if (r == TM_ECODE_FAILED) {
TmqhOutputPacketpool(tv, p);
TmThreadsSetFlag(tv, THV_FAILED);
@ -525,13 +526,13 @@ void *TmThreadsSlotVar(void *td) {
tv->tmqh_out(tv, p);
/* now handle the post_pq packets */
while (s->s->slot_post_pq.top != NULL) {
Packet *extra_p = PacketDequeue(&s->s->slot_post_pq);
while (s->slot_post_pq.top != NULL) {
Packet *extra_p = PacketDequeue(&s->slot_post_pq);
if (extra_p == NULL)
continue;
if (s->s->slot_next != NULL) {
r = TmThreadsSlotVarRun(tv, extra_p, s->s->slot_next);
if (s->slot_next != NULL) {
r = TmThreadsSlotVarRun(tv, extra_p, s->slot_next);
if (r == TM_ECODE_FAILED) {
TmqhOutputPacketpool(tv, extra_p);
TmThreadsSetFlag(tv, THV_FAILED);
@ -550,13 +551,15 @@ void *TmThreadsSlotVar(void *td) {
}
SCPerfUpdateCounterArray(tv->sc_perf_pca, &tv->sc_perf_pctx, 0);
for (slot = s->s; slot != NULL; slot = slot->slot_next) {
if (slot->SlotThreadExitPrintStats != NULL) {
slot->SlotThreadExitPrintStats(tv, slot->slot_data);
s = (TmSlot *)tv->tm_slots;
for ( ; s != NULL; s = s->slot_next) {
if (s->SlotThreadExitPrintStats != NULL) {
s->SlotThreadExitPrintStats(tv, s->slot_data);
}
if (slot->SlotThreadDeinit != NULL) {
r = slot->SlotThreadDeinit(tv, slot->slot_data);
if (s->SlotThreadDeinit != NULL) {
r = s->SlotThreadDeinit(tv, s->slot_data);
if (r != TM_ECODE_OK) {
TmThreadsSetFlag(tv, THV_CLOSED);
pthread_exit((void *) -1);
@ -569,77 +572,67 @@ void *TmThreadsSlotVar(void *td) {
pthread_exit((void *) 0);
}
TmEcode TmThreadSetSlots(ThreadVars *tv, char *name, void *(*fn_p)(void *)) {
uint16_t size = 0;
/**
* \brief We set the slot functions
*
* \param tv Pointer to the TV to set the slot function for.
* \param name Name of the slot variant.
* \param fn_p Pointer to a custom slot function. Used only if slot variant
* "name" is "custom".
*
* \retval TmEcode TM_ECODE_OK on success; TM_ECODE_FAILED on failure.
*/
TmEcode TmThreadSetSlots(ThreadVars *tv, char *name, void *(*fn_p)(void *))
{
if (name == NULL) {
if (fn_p == NULL) {
printf("Both slot name and function pointer can't be NULL inside "
"TmThreadSetSlots\n");
goto error;
}
else
} else {
name = "custom";
}
}
if (strcmp(name, "1slot") == 0) {
size = sizeof(Tm1Slot);
tv->tm_func = TmThreadsSlot1;
} else if (strcmp(name, "1slot_noout") == 0) {
size = sizeof(Tm1Slot);
tv->tm_func = TmThreadsSlot1NoOut;
} else if (strcmp(name, "1slot_noin") == 0) {
size = sizeof(Tm1Slot);
tv->tm_func = TmThreadsSlot1NoIn;
} else if (strcmp(name, "1slot_noinout") == 0) {
size = sizeof(Tm1Slot);
tv->tm_func = TmThreadsSlot1NoInOut;
} else if (strcmp(name, "varslot") == 0) {
size = sizeof(TmVarSlot);
tv->tm_func = TmThreadsSlotVar;
} else if (strcmp(name, "custom") == 0) {
/* \todo this needs to be changed to support slots of any size */
size = sizeof(Tm1Slot);
if (fn_p == NULL)
goto error;
tv->tm_func = fn_p;
} else {
printf("Error: Slot \"%s\" not supported\n", name);
goto error;
}
tv->tm_slots = SCMalloc(size);
if (tv->tm_slots == NULL)
goto error;
memset(tv->tm_slots, 0, size);
return TM_ECODE_OK;
error:
return TM_ECODE_FAILED;
}
void Tm1SlotSetFunc(ThreadVars *tv, TmModule *tm, void *data) {
Tm1Slot *s1 = (Tm1Slot *)tv->tm_slots;
if (s1->s.SlotFunc != NULL)
printf("Warning: slot 1 is already set tp %p, "
"overwriting with %p\n", s1->s.SlotFunc, tm->Func);
s1->s.SlotThreadInit = tm->ThreadInit;
s1->s.slot_initdata = data;
s1->s.SlotFunc = tm->Func;
s1->s.SlotThreadExitPrintStats = tm->ThreadExitPrintStats;
s1->s.SlotThreadDeinit = tm->ThreadDeinit;
tv->cap_flags |= tm->cap_flags;
}
/**
* \brief Appends a new entry to the slots.
*
* \param tv TV the slot is attached to.
* \param tm TM to append.
* \param data Data to be passed on to the slot init function.
*/
void TmSlotSetFuncAppend(ThreadVars *tv, TmModule *tm, void *data)
{
TmSlot *s = (TmSlot *)tv->tm_slots;
void TmVarSlotSetFuncAppend(ThreadVars *tv, TmModule *tm, void *data) {
TmVarSlot *s = (TmVarSlot *)tv->tm_slots;
TmSlot *slot = SCMalloc(sizeof(TmSlot));
if (slot == NULL)
return;
memset(slot, 0, sizeof(TmSlot));
slot->SlotThreadInit = tm->ThreadInit;
@ -647,13 +640,14 @@ void TmVarSlotSetFuncAppend(ThreadVars *tv, TmModule *tm, void *data) {
slot->SlotFunc = tm->Func;
slot->SlotThreadExitPrintStats = tm->ThreadExitPrintStats;
slot->SlotThreadDeinit = tm->ThreadDeinit;
tv->cap_flags |= tm->cap_flags;
if (s->s == NULL) {
s->s = slot;
if (s == NULL) {
tv->tm_slots = slot;
slot->id = 0;
} else {
TmSlot *a = s->s, *b = NULL;
TmSlot *a = s, *b = NULL;
/* get the last slot */
for ( ; a != NULL; a = a->slot_next) {
@ -665,6 +659,8 @@ void TmVarSlotSetFuncAppend(ThreadVars *tv, TmModule *tm, void *data) {
slot->id = b->id + 1;
}
}
return;
}
#if !defined OS_WIN32 && !defined __OpenBSD__

@ -36,7 +36,8 @@ enum {
typedef struct TmSlot_ {
/* function pointers */
TmEcode (*SlotFunc)(ThreadVars *, Packet *, void *, PacketQueue *, PacketQueue *);
TmEcode (*SlotFunc)(ThreadVars *, Packet *, void *, PacketQueue *,
PacketQueue *);
TmEcode (*SlotThreadInit)(ThreadVars *, void *, void **);
void (*SlotThreadExitPrintStats)(ThreadVars *, void *);
@ -46,38 +47,29 @@ typedef struct TmSlot_ {
void *slot_initdata;
void *slot_data;
/**< queue filled by the SlotFunc with packets that will
* be processed futher _before_ the current packet.
* The locks in the queue are NOT used */
/* queue filled by the SlotFunc with packets that will
* be processed futher _before_ the current packet.
* The locks in the queue are NOT used */
PacketQueue slot_pre_pq;
/**< queue filled by the SlotFunc with packets that will
* be processed futher _after_ the current packet. The
* locks in the queue are NOT used */
/* queue filled by the SlotFunc with packets that will
* be processed futher _after_ the current packet. The
* locks in the queue are NOT used */
PacketQueue slot_post_pq;
/* linked list, only used by TmVarSlot */
struct TmSlot_ *slot_next;
/* slot id, only used my TmVarSlot to know what the first slot is */
int id;
int id; /**< slot id, only used my TmVarSlot to know what the first
* slot is. */
/* linked list, only used when you have multiple slots(used by TmVarSlot) */
struct TmSlot_ *slot_next;
} TmSlot;
/* 1 function slot */
typedef struct Tm1Slot_ {
TmSlot s;
} Tm1Slot;
/* Variable number of function slots */
typedef struct TmVarSlot_ {
TmSlot *s;
} TmVarSlot;
extern ThreadVars *tv_root[TVT_MAX];
extern SCMutex tv_root_lock;
void Tm1SlotSetFunc(ThreadVars *, TmModule *, void *);
void TmVarSlotSetFuncAppend(ThreadVars *, TmModule *, void *);
void TmSlotSetFuncAppend(ThreadVars *, TmModule *, void *);
ThreadVars *TmThreadCreate(char *, char *, char *, char *, char *, char *,
void *(fn_p)(void *), int);
ThreadVars *TmThreadCreatePacketHandler(char *, char *, char *, char *, char *,
@ -112,6 +104,4 @@ int TmThreadsCheckFlag(ThreadVars *, uint8_t);
void TmThreadsSetFlag(ThreadVars *, uint8_t);
void TmThreadsUnsetFlag(ThreadVars *, uint8_t);
#endif /* __TM_THREADS_H__ */

@ -2202,7 +2202,7 @@ void TmModuleCudaMpmB2gRegister(void)
void *CudaMpmB2gThreadsSlot1(void *td)
{
ThreadVars *tv = (ThreadVars *)td;
Tm1Slot *s = (Tm1Slot *)tv->tm_slots;
TmSlot *s = (TmSlot *)tv->tm_slots;
SCCudaPBPacketsBuffer *data = NULL;
B2gCudaMpmThreadCtxData *tctx = NULL;
char run = 1;
@ -2216,8 +2216,8 @@ void *CudaMpmB2gThreadsSlot1(void *td)
SCLogDebug("%s starting", tv->name);
if (s->s.SlotThreadInit != NULL) {
r = s->s.SlotThreadInit(tv, s->s.slot_initdata, &s->s.slot_data);
if (s->SlotThreadInit != NULL) {
r = s->SlotThreadInit(tv, s->slot_initdata, &s->slot_data);
if (r != TM_ECODE_OK) {
EngineKill();
@ -2225,10 +2225,10 @@ void *CudaMpmB2gThreadsSlot1(void *td)
pthread_exit((void *) -1);
}
}
memset(&s->s.slot_pre_pq, 0, sizeof(PacketQueue));
memset(&s->s.slot_post_pq, 0, sizeof(PacketQueue));
memset(&s->slot_pre_pq, 0, sizeof(PacketQueue));
memset(&s->slot_post_pq, 0, sizeof(PacketQueue));
tctx = (B2gCudaMpmThreadCtxData *)s->s.slot_data;
tctx = (B2gCudaMpmThreadCtxData *)s->slot_data;
TmThreadsSetFlag(tv, THV_INIT_DONE);
while(run) {
@ -2245,7 +2245,7 @@ void *CudaMpmB2gThreadsSlot1(void *td)
* If the MPM is configured to use multiple CUstreams, buffer (1) and buffer (2) are
* processed in parallel using multiple streams; In this case
* data_queues[tctx->tmq_streamq->id] will contain the results of packet buffer (2). */
r = s->s.SlotFunc(tv,
r = s->SlotFunc(tv,
(Packet *)data,
(void *)tctx,
(PacketQueue *)&data_queues[tv->inq->id],
@ -2270,12 +2270,12 @@ void *CudaMpmB2gThreadsSlot1(void *td)
}
}
if (s->s.SlotThreadExitPrintStats != NULL) {
s->s.SlotThreadExitPrintStats(tv, s->s.slot_data);
if (s->SlotThreadExitPrintStats != NULL) {
s->SlotThreadExitPrintStats(tv, s->slot_data);
}
if (s->s.SlotThreadDeinit != NULL) {
r = s->s.SlotThreadDeinit(tv, s->s.slot_data);
if (s->SlotThreadDeinit != NULL) {
r = s->SlotThreadDeinit(tv, s->slot_data);
if (r != TM_ECODE_OK) {
TmThreadsSetFlag(tv, THV_CLOSED);
pthread_exit((void *) -1);

Loading…
Cancel
Save